Hacker News new | ask | show | jobs
by vimslayer 2559 days ago
There have been a few posts like this, and the discussion always seems to focus on plain JavaScript vs TypeScript. I'd like to see some talk about Flow vs TypeScript instead. We have what I'd call a medium-sized project (~30k loc) written with Flow and TypeScript's superior tooling is indeed attractive enough that we too have been thinking about making the switch.

Having used both, there are a few features in Flow that I'd miss. I think classes being nominal is a good approach and the ability to declare new nominal types is useful. Otherwise Flow's type system is structural, like TypeScript's. Function parameter type inference is also very nice feature, so I can make simple module- or function-local helper functions without needing to specify the parameter types explicitly. Having a syntax for specifying parameter variance allows for a more sound type system in some areas.

Performance has historically been pretty bad but it's been getting better with every release. The tooling has also seen some improvements after Facebook nuked their own Nuclide-editor project and moved on to endorsing Language Server Protocol and VSCode. It's still far, far behind TypeScript, though. It's also a bit worrying that the community seems to be getting smaller, not bigger, with posts like this popping up.

2 comments

A few more random thoughts that popped into my head:

Flow's Windows support is pretty buggy. We have some team members who prefer Windows as their dev machine and it looks... painful.

Flow supports the upcoming `?.` operator and overall they seem more open to introducing features that are in a development phase and might be changed/deprecated in the future. I guess it's a matter of perspective if that's good or bad, but man I'm going to be sad if we end up making the change and I have to convert all those nice and clean `foo?.bar?.baz` chains into some unreadable multiline monstrosity or calls to some random getter library.

Flow's exact object types [1] are really useful and have prevented actual bugs when used with optional properties. TypeScript's concept of "freshness" [2] does prevent many if not most of these bugs though.

[1]: https://flow.org/en/docs/types/objects/#toc-exact-object-typ...

[2]: https://basarat.gitbooks.io/typescript/docs/types/freshness....

> Flow supports the upcoming `?.` operator and overall they seem more open to introducing features that are in a development phase

It's funny because Typescript started out by trying to get ahead of a lot of features and "settling down" to trying to stick to (mostly) only TC39 Stage 3+ features has been a maturation that has been good for the language. It's interesting that Flow seems to be moving the other direction.

A benefit to making it easier to pipeline Typescript inside Babel is that it is no longer entirely on Typescript to transpile every possible wishlist language proposal. This is also why a lot of people preferred Flow because you could just slot Flow checking before or after certain transforms. Typescript is getting better about fitting into the middle of a Babel transform stack so that you might have some basic preprocessing steps of Stage 2 or earlier or non-standards track things that Babel supports before type checking.

(The Optional Chaining proposal for `?.` is currently in Stage 2 in TC39. Indications seem to be that at least some of the Typescript devs are ready to champion that feature in the very minute it hits Stage 3.)

Can’t wait for the, “Elvis operator” to land. Going to remove so much code!
Ironically, one of the easier ways TypeScript has been able to work quickly is by skipping the type inference Flow does. It’s a trade off. The Flow team was advised that this approach would have performance problems early on in the project, and opted to focus on type system features first and perf second.
Flow's perf issues has more to do with bugs than anything. Its usually pretty near instant even on big projects, but do one little thing wrong somewhere that hits an edge case and everything goes to hell and you'll never find where it came from.