There are two major players in this field one is Flow written in ocaml by facebook and second is TypeScript written in TypeScript by microsoft.
Besides those there is new kid in the neighborhood called hegel written in JavaScript (with Flow and hegel) by ukrainian developer Artem Kobzar. hegel is not ready for prime time but it has much better design decisions and goals around type system then TypeScript and is written in JavaScript opposite to facebook's decision to use ocaml for JavaScript type system which greatly limits contributions from community.
This Repo is for comparing those three and tracking progress.
In this section we compare features and how well they are implemented.
- note 01: no IDE support bullcrap in this section.
- note 02:
???
links are used instead ofabbr
tags since those are not supported by github in readme.
Criteria | TypeScript | Flow | Hegel |
---|---|---|---|
Type safe try/catch/throw | No, #13219 | No, #2470 | Yes |
Immutability | Unusable, #13347 | Yes | Yes |
Type inference | Sometimes, ??? | Mostly, ??? | Yes, ??? |
Enforce use of function return value | No | No, #3914 | Yes |
Prevent implicit type conversion | Sometimes, ??? | Sometimes, ??? | Yes, ??? |
Correctly balanced nominal and structural typing | No, ??? | Yes | Yes |
Library of type definitions | Good, DefinitelyTyped | There is something, flow-typed | Same as TypeScript |
Ability to enforce no extra props | Sometimes, but it's hacky | Yes By Default | Yes By Default |
Attempt to prevent runtime TypeErrors | No non-goal | Mostly, it's design goal | Mostly, it's design goal |
Type guards | Unusable, ??? | No, ??? | No |
Assertion functions | Unusable, ??? | No, #112, ??? | No |
Conditional types | Yes | No, #6055, ??? | No |
Term | Meaning |
---|---|
Yes By Default | It is implemented, it works and is turned on by default |
Yes | It is implemented and it works (it may or may not be turned on by default) |
Mostly | It is implemented and mostly covers use cases |
Sometimes | It has poor implementation that sometimes works and sometimes does not |
Unusable | It has so poor implementation that it rarely makes any difference |
No | It is not implemented |
No non-goal | It is not implemented and it will not be implemented in future |
In this section we compare how popular each solution is amongs most impactful JavaScript projects.
Project | Choice | Proof |
---|---|---|
babel | Flow | 1 |
React | Flow | 1 |
Redux v1, v2 and v3 | Flow | 1 2 3 |
Redux v4 | TypeScript | 1 |
Vue.js v2 | Flow | 1 |
Angular v2+ | TypeScript | 1 |
date-fns | both | 1 2 |
meteor | TypeScript but very few ts files | 1 |
NEXT.js | TypeScript but very few ts files | 1 |
Gatsby v1 | Flow | 1 |
Gatsby v2 | TypeScript but very few ts files | 1 |
Rollup | TypeScript but very few ts files | 1 |
ember.js v3 | TypeScript but very few ts files | 1 |
Aurelia | TypeScript but no ts files?! | 1 |
Yarn v1 | Flow | 1 |
Yarn v2 (berry) | TypeScript | 1 |
NestJS | TypeScript | 1 |
AdonisJS | TypeScript | 1 |
Relay | Flow | 1 |
Many JavaScript projects are not using any type checking tool at all and many who use TypeScript don't go all in on it and have only about 1/4 of files converted to TypeScript
Also Flow seems to be loosing to TypeScript since some projects which started with flow did switch to TypeScript (like Redux, Gatsby and Yarn)
feel free to open issue or pull request to point out any mistake (like missing punctuation or typo) or mission/inaccurate information.