TypeScript vs. FlowType

BASARAT
3 min readAug 4, 2016

--

People definitely see the value of TypeScript and at the very least the tooling it makes possible. Even people that initially discredited TypeScript preventing bugs can now be seen exploring this thriving ecosystem (I am sure you know a few of these people).

However people continue to ask me (and others) about FlowType vs. TypeScript. Of course my opinion is biased. Honestly both are excellent choices. Its like writing good documentation and having empathy for your fellow developers. If you do that, then you are good person. My reasons for TypeScript preference are:

  • `.ts/.tsx` extension. I like having type annotation in a .ts file whereas flow encourages you to have `.js` extension which feels like an upgrade / deprecations nightmare.
  • Bootstrapped. I like that TypeScript is written in TypeScript (JavaScript) and just as portable as JavaScript. FlowType is in ocaml.
  • Third party JavaScript definitions : If you use jquery (or lodash or momentjs or your favorite JavaScript lib) and want to use it in a safe way TypeScript provides a very nice story aka DefinitelyTyped.
  • Of course the current TypeScript ecosystem is significantly bigger then the flow one so if you are looking for future safety the answer is fairly obvious.

The FlowType team is doing a great job and I am really happy to see Facebook providing it as free OSS software. Indeed a few of its ideas (e.g. Intersection Types / Union Types / Nullable concept) have paved the way to better JavaScript analysis for TypeScript too 🌹.

Debunking FlowType myths

There are a few misunderstanding out there that I have seen that are worth mentioning:

FlowType lets me just use JavaScript vs. TypeScript forces me to a new language

Both Flow and TypeScript, require you to be explicit type-checking of a particular file. For TypeScript the differentiator is the file extension .js vs. .ts whereas for Flow it is a comment on top of the file // @flow. As soon as you switch either on in your project:

  • You will most likely get errors in both TS and Flow e.g. for any undeclared variables.
  • You get additional syntax opportunities that is a superset of JS.

More on bootstrapping

Because TypeScript is written in TypeScript (which in turn is just JavaScript), it makes a lot of things possible e.g. in browser playgrounds : http://www.typescriptlang.org/play/. Also I’m pretty clear on which project’s source code I would want to look at:

Its difficult to work on a developer tool without actually getting benefit to yourself from working on the developer tool. Suspect flow will go through a rewrite (after getting sufficiently annoyed by OCAML tooling) at some point, but TypeScript is already there.

Can’t I use both?

You can. But beware that there are significant syntax and semantic differences between the two.

Others

Other teams that have evaluated both and have made a similar choice of using TypeScript

If you liked this post click on the heart below. Any questions? I love to help🌹.

--

--