Search posts, tags, users, and pages
TypeScript has caught up with a lot of issues, which originally prevented Facebook from utilizing it (file by file opt in, etc) ... It seems it is superior to Flow in so many ways.. why is Facebook still investing in Flow and not jumping on the TypeScript bandwagon?
For the same reason that TypeScript is superior to Flow in many ways, Flow is superior to TypeScript in many ways. In practice, the two have just made different fundamental decisions that have resulted in tradeoffs.
A few examples:
Nullability. Flow started from day one with Nullability in mind, and that was also one of primary reasons the project was started in the first place. Typescript was not, but adding nullability support in after the fact is not an easy thing to do because it changes the meaning of existing code. While Typescript plans on adding strict nullability checking in v2.0 (some recent great PRs have landed), you'll still need to opt-in with a compiler flag and many existing libraries that export types will have to either update or just be unsafe to nulls.
Nominal vs Structural types. Type checking languages open a lot of questions, there are a lot of ways to do it. Typical object-oriented languages like Java or C# typically use Classes and Interfaces to implement Nominal types - that is the name of the class or interface determines if something adheres to a type or not. TypeScript chose this path, and therefore relies heavily on the use of Interfaces and Classes. Typically functional languages like Haskell or ML implement Structural types - that is the structure of the data within some value matches the type signature or not. Flow chose this approach because it matched up with how the team saw JavaScript being used, and helped to type things like returning plain Objects with fields.
New Language. TypeScript is actually a new language, it adds new kinds of things that JavaScript doesn't have like Enums, Interfaces and Class properties. It also explicitly excludes some stuff that you could do in JavaScript, but doesn't fit well in TypeScript. Of course, this is a cool thing! Flow decided to make a different decision and only type existing JavaScript. This has an interesting property where type-checking and compilation can be separated into different steps. In order to turn Flow code into JavaScript, you simply remove the type hints (or comment them out). This ended up being really important for Facebook's build tools (we have a LOT of JavaScript) but also the team felt confident that such an approach was interesting in its own right.
Also, at the end of the day, Flow has improved greatly from watching what TypeScript does and TypeScript has improved from watching what Flow does. The two teams often talk to each other to share ideas, and even if all of the above weren't true, I think some healthy competition in technical projects is a great driver of progress.