Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

TypeScript over Flow

* The language service is superb (and will soon have a documented API). Just try the playground: http://www.typescriptlang.org/Playground/ or Visual Studio. Flow has some sort of open tooling, but its comparatively poor for now (e.g. its autocomplete rarely gives suggestions, needs to be augmented with other tools)

* You can actually export types. Flow lets you do it, but jstransform generates code that throws at runtime (https://github.com/facebook/jstransform/pull/54). This is really annoying and makes Flow unusable for any serious production work right now (for me)

* You can declare modules that are just functions. Flow only lets you declare modules that contain things. This is also annoying and makes Flow unusable with many modules on npm aswell. TypeScript on the other hand has excellent support for all of the following: AMD, CommonJS and object (namespaced) modules. Modules are a bit confusing and rigid and take some time to figure out though.

* Passing all compilation units to the compiler rather than working inside an entire folder based on a config file is a lot more flexible.

* Boudned generics. TypeScript lets you add restrictions to your generics e.g. `interface Set<T extends Eq> { ... }`. Afaik flow doesnt have them yet.

* Faster, more open development. Compare TypeScript's daily commits, code reviews and pull requests with flow's monthly code-dump ("sync changes to upstream")

* Doesn't pretend its not a compile-to-JS language. Flow is being marketed by Facebook as JavaScript but it isn't (maybe they want to avoid being bashed by the coffeescript-hater crowd? having strong type inference does not a JavaScript make) TypeScript clearly states its a compile-to-JS language. Both are pretty much the same thing in this regard.

Flow over TypeScript:

* Much sounder type system. Null and (most) undefined values are properly modeled. Generics don't have weird behavior [1] in some cases. This is truly the best thing Flow has over TS.

* Product types. TypeScript only has function product types (overloads), Flow also supports product types on objects, which is really useful given the nature of JS objects (e.g. lets you model lodash.extend properly)

* A couple of extra ES6 goodies (e.g. destructuring). TypeScript will be catching up soon though.

* Much better type inference. In typescript types stop flowing through functions that are not arguments to function calls. In flow they continue to... erm, flow, so its possible to write most of your module without using any type annotations whatsoever. Now, this might sound like its important, but in practice its not that important - its best to annotate all functions with types anyway as error messages soon become confusing or misleading otherwise (the line where an inconsistency occurred is much further away than the place with the actual error)

* JSX. I find this not-so-useful to be honest, especially with the newest strongly-tied-to-React incarnation of the JSX compiler which is a lot less nicer than the older compiles-to-function-calls version. Though its really nice to have typechecked HTML-like templates, I suppose.

Even more info here:

[1]: https://github.com/Microsoft/TypeScript/issues/1265



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: