3 ms·
TS bolts on a straightforward nominative type system without type unions (or non-nullable types), so it can't handle a variable typed as `number | string`, it'l
by masklinn 12y ago
TS bolts on a straightforward nominative type system without type unions (or non-nullable types), so it can't handle a variable typed as `number | string`, it'll immediately drop down to `any`. That is, flow aims to remain useful in the face of more JS idioms. It won't make a difference between nullable and non-nullable either, so AFAIK
function length(x) {
return x.length;
}
length(null);
can never be a compile-time error in typescript.
- Arnavion 12y agoUnion types are present in the master branch of the TS compiler. The compiler also uses instanceof and typeof === ... to reduce the range of types inside a branch, similar to Flow.
- johnny_reilly 12y agoDue to ship with TypeScript 1.4 - see recent blog post: http://blogs.msdn.com/b/typescript/archive/2014/11/18/what-s-new-in-the-typescript-type-system.aspx http://blogs.msdn.com/b/typescript/archive/2014/11/18/what-s...
- DougBTX 12y agoYep, here's some related discussion: https://github.com/Microsoft/TypeScript/issues/185 https://github.com/Microsoft/TypeScript/issues/185 tl;dr: they want to support both of those features, the question is what syntax to use and how to introduce those features into the existing ecosystem.