4 ms·
I went through a similar process and chose TS > Flow. - Renaming to .ts and .tsx is nicer than adding comments, because it integrates better with tooling (comp
by bcherny 9y ago
I went through a similar process and chose TS > Flow.
- Renaming to .ts and .tsx is nicer than adding comments, because it integrates better with tooling (compile all files that end with .ts) and it's easier to see at a glance what's ported
- You can always compile TS to ES2018 and run that through Babel, if you like. TSLint -> ESLint is indeed a change, though you can continue to use most of ESLint for TS [0]
- As a rule, TS is compile time only. There are a few exceptions, but that's almost always the case.
For me the advantages of TS are:
- Huge library of community written typings for JS libs
- Mapped types
- Full support for literal types
- Read only types
That said, I really like Flow's co/contravariance annotations, and the corresponding $Supertype and $Subtype functions. That, and nominal typing can be really convenient (coming to TS soon, hopefully).
[0] https://github.com/eslint/typescript-eslint-parser https://github.com/eslint/typescript-eslint-parser
- nothrabannosir 9y ago> As a rule, TS is compile time only. There are a few exceptions Sorry just for my information: which ones are those?
- charrondev 9y agoI'm pretty sure generators need a runtime component. TS supports them down to ES3. Async/await gets transformed to generators too afaik.
- nothrabannosir 9y agoThe typescript compiler is a type checker and a cross-JS-version transpiler in one. Runtime code introduced to support generators in lower ES versions isn't exactly the same as the type system needing a runtime component. It's more like "the Babel part" which is included in TS. I personally don't think it's an attractive part of TS; it's confusing, and it's just duplicating efforts that Babel already does best. But that's just me.
- klibertp 9y ago> That, and nominal typing can be really convenient (coming to TS soon, hopefully). I think you meant structural typing? TS was always nominally typed. I searched for a bit and it looks like TS also supports structural typing with explicit interfaces, and I think Flow tries to infer such types? I don't use either one, so I'm not sure about the details.
- cowmoo728 9y agoTS is structurally typed. You declare the fields you expect on a type or interface, and as long as an object has at least those fields, it will typecheck. Nominal typing would mean that you could declare type A and type B with identical fields, but if something is declared as A, it cannot be used in place of B. TS has a strange workaround to get nominal typing for now: https://basarat.gitbooks.io/typescript/docs/tips/nominalTyping.html https://basarat.gitbooks.io/typescript/docs/tips/nominalTypi...
- klibertp 9y agoThat's interesting - I'm almost sure last time I checked (possibly a couple years back) TS used nominal typing. Do you know if this changed at some point, or is it just my memory being bad?
- RyanCavanaugh 9y agoTypeScript has used structural typing since the beginning. Classes used to be nominal, but changed to structural (except for classes with private fields) at some point.
- klibertp 9y ago> Classes used to be nominal, but changed to structural Ah, ok, makes sense. I think I was last looking at TS around version 1.1 or something like that. Thanks!