But the biggest TS advantage has to be the size of the ecosystem. There are quite a few libraries written in TypeScript, and there are type definitions for pretty much all popular JS libs (and quite a lot of obscure ones). The Flow defs ecosystem seems to be fairly anaemic by comparison.
* TypeScript has larger community.
* Flow requires Babel. TypeScript doesn't. One less dependency to worry about. And in my experience TypeScript compiler produces better JavaScript than Babel.
* Flow is written in OCaml. It could probably make it more difficult to install than TypeScript.
P.S. React works fine with TypeScript. I haven't played with React Native though.
That's a very good reason. I wish there were more community-provided types for flow. I think Immutable.js has only just fixed the last issues, but that's really been bugging me for the last few months. ("no default export" and "isEquals".)
* Flow requires Babel.
Not a huge deal for me, since React Native already requires Babel, and I personally like working with Babel. I use a number of Babel plugins, such as "transform-decorators-legacy" and "module-resolver".
* Flow is written in OCaml. It could probably make it more difficult to install than TypeScript.
Not at all, installation was very quick and easy. You can use either npm or Homebrew.
One technical limitation that complicate contributions to the flow-typed repository is that there is no way of writing typings that depend on other libraries' types [1]. For instance, flow-typed has a library definition for `rxjs`, but it is not possible to e.g. add a definition for `redux-observable` that reuses the RxJS `Observable<T>` type, because there is no way to express that the typings of `redux-observable` neeed the ones of `rxjs` to function. So typings for such closely related libraries tend to not exist in flow-typed.
To work around this problem, some libraries like styled-components require you to manually include the library definition files it requires in your `.flowconfig` [2], but this is a rather hacky workaround.
[1]: https://github.com/flowtype/flow-typed/issues/16
[2]: https://github.com/styled-components/styled-components/blob/...
So are you saying that there are no flow types for redux-observable? I guess that's not a deal-breaker, since flow-typed will just generate stubs. Also, it looks like react-observable is a super high level abstraction, so I'm not even going to be writing that much code.
[1] https://www.youtube.com/watch?v=AslncyG8whg&feature=youtu.be
Could you elaborate on that please? Is it impossible to skip Babel when using React Native?
> Not at all. Installation is very fast and easy.
(Last time I checked Flow npm package gives you binaries.)
I'm sure Flow installs fine in "standard" environments, like an OSX laptop. I was thinking about more weird places, like CI servers where you can't fully control the environment. I was burned enough about stuff like that in the past.
Yes, the React Native packager depends on Babel, and uses a react-native preset. When you start a new project, you get this default .babelrc:
{
"presets": [
"react-native-stage-0"
]
}
They basically wrote their own version of webpack, to solve some performance problems and make development as fast as possible.Here's the only issue I found, which is now closed: https://github.com/flowtype/flow-typed/issues/247
> TypeScript has larger community.
It kind of depends. In some circles Flow is bigger. Mind that it is heavily entrenched in everything Facebook does, so it's treated as a built-in, first-class citizen in many circles (e.g. React Native).
> Flow requires Babel. TypeScript doesn't.
I'm not sure I agree. Objectively, depending on the kind of Flow you write, you don't really require any transpilation step.
Plus, subjectively, using Babel with TypeScript should not be frowned upon - there's a lot of advantages that Babel can provide that are outside of the scope of what TypeScript tries to do. Personally I use it to provide shims (via babel-preset-env) so I can target older browsers based on version configurations.
I find this especially useful for node projects, where there is less of a case for using Babel etc (node 7 supports all the JS features I want).
With Typescript, you have to write custom Type Guards functions, whereas Flow is smart enough to infer type
With TS v2.2, I don't need to do any ugly hacks on TS to fit into pre-existing JS code.
Also, react support has been excellent since...TS 1.7 (or before?). TSX checks for React PropTypes <div on_click={...}> or <div onClick={someBool}> so this gets rid of most of my silly mistakes :)
Flow is definitely a better type system than TS. TS types are "strong" in the same way as Java types. Flow is basically OCaml types, so a similar type system to OCaml, Haskell or Elm (except that you can give things `any` type). I am sure I will chose Flow over TS for that reason.
A ML-type type system (Flow, OCaml, Haskell, Elm, etc) is very powerful in that you can have abstract types, which means you can do basic composition of them. Things like the Maybe or Result monad for instance, which is very useful (and simple).
Typescript on the other hand let's you use the basic JS types, but it's not as extensible.
What do you mean by "abstract types"? TS's type system is based around structural interfaces, so you're almost always working with non-concrete types.
It also supports discriminated unions, and you can emulate nominal typing with abstract tag properties.
https://www.typescriptlang.org/docs/handbook/advanced-types.... https://basarat.gitbooks.io/typescript/docs/tips/nominalTypi...
Have a look here: http://djcordhose.github.io/flow-vs-typescript/flow-typescri...
I've been really enjoying Flow, and I have experienced all of the benefits mentioned in this article. I'm using VSCode, and the Flow integration is really good. Feels like a full IDE for Javascript, without being bloated and slow. (Startup is a little slower than Sublime, but it's very fast once everything has loaded.)
I'm wondering if I'm missing out on anything by choosing Flow instead of Typescript.
I've been developing React and React Native apps, and it seems like Flow is the default choice for that ecosystem. Has anyone switched from Flow to Typescript, and how did it go?