Adopting Flow & TypeScript
Jamie Kyle
38024

A couple of points here.

First, you only mention inferencing in the context of Flow. But it is worth pointing out that TypeScript does plenty of type inferencing itself. It just doesn’t do as much as Flow.

But that leads me to my second point which is about your example. I’m a bit surprised that Flow generates the message “The operand of an arithmetic operation must be a number”. While that is true for the operator, the code itself is not necessarily an error because of implicit conversions. So I would argue that in this case, the TypeScript compiler is more correct than the Flow compiler because it does not (nor should it, IMHO) flag an error. Granted, I don’t think relying on implicit conversions is a very good practice, but I think a better example is warranted here.

Third, if you are trying to migrate an existing code base I can definitely see how Flow would be really useful for migrating because of its more extensive inferencing. You also make a valid point about type coverage. Personally, I use the “no implicit any” option for all my TS code, so I’m essentially getting 100% type coverage out of the gate (assuming you don’t go around adding lots of explicit any types, which will defeat the purpose of the flag). As you say, for an existing code base that can be quite a burden. But I just wanted to reiterate what you said near the end of the post about not relying too much on inferencing. Type annotations are a good thing not just because they lead to better error messages, as you say, but also because they greatly improve the experience for people reading your code. Having used TypeScript for quite a while, when I end up back in vanilla Javascript I’m immediately aware of the lack of type information when I see a function like `function validate(x) { … }` and I’m thinking “what is x? How do I know what valid values are?”.

Like what you read? Give Michael Tiller a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.