Mircea Dinoiu

Flow to TypeScript

October 10, 2019

I am late to this debate and you can already find a ton of content on the web comparing these two products, however this article is mostly going to be talking about my experience of migrating from one to another.
This material describes the differences very well.

After using Flow every day for few years, I challenged myself to switch one of my apps to TypeScript.
I had both good and poor experiences with Flow so it made sense to check if TypeScript fits my needs better. The codebase I was going to switch had to be small but complex enough, so I ended up porting ~100 .jsx files to .tsx.
There are tools that you can use to automate the process. However I did it all manually in order to learn as much as possible.

Here are the highlights of my experience:

  • I was pleasantly surprised to see that a lot of npm packages already had the typings bundled in. I like the stronger community of TypeScript whereas Flow’s flow-typed is not as rich.
    It’s also worth mentioning that TypeScript is proactive about you adding the missing typings for 3rd party libraries (going as far as throwing an error about it).
    On the other side, if you didn’t know flow-typed existed.. you are not going to be type safe.
  • A thing I like about the Flow setup: I can write sketchy code in order to prototype something quickly. It fails Flow, but the compiler outputs. TypeScript is a compiler, so it won’t let you proceed until you fix the compilation errors.
  • I found TypeScript’s errors harder to read. They are very long and don’t clearly state where the error is happening. I might get used to it though.
  • Flow has utility types that are not built in TypeScript (eg: $Values, $Keys), but I found this amazing package that brings a bunch of them to TypeScript
  • TypeScript has fantastic IDE support which is the thing I like the most. It makes refactoring and autocomplete so much easier.

Conclusions

When I started the migration I was expecting to encounter many more challenges, but it was a pretty smooth transition.

My opinion is that you are probably going to end up being more productive using TypeScript rather than Flow mostly because of strong IDE support and richer 3rd party typings.

I am pleased with the outcome of the migration so the app is going to be developed with TypeScript instead of Flow from now on.

As for future apps, the odds will be in TypeScript’s favor unless it gives me enough reasons to consider differently.


Kyle Mathews
Front End Dev living in Bay Area. I love video games and snowboarding.