4 ms·
TypeScript 1.8 already has unions and custom type guards! You can use them today. Woohoo! (Looking forward to those non-nullable types, though.)
by samps 10y ago
TypeScript 1.8 already has unions and custom type guards! You can use them today. Woohoo! (Looking forward to those non-nullable types, though.)
- shuzchen 10y agoI was just about to complain how TS fails totally for typechecking backbone models or immutablejs datastructures: both situations where obj.get("foo") and obj.get("bar") return a particular type but there's no way of having TS handle that except defining them as any. But it turns out string literal types in 1.8 will make that work. And this was out since February! I should reevaluate TS for my omniscient project.
- rubber_duck 10y agoIIRC there is no ergonomic way to define typed records for Immutable.js ?
- girvo 10y agoIf I recall correctly, you still can't type Immutable.js nicely with Flow, let alone Typescript, so I'm not surprised tbh
- danielearwicker 10y agoI've been playing with https://github.com/danielearwicker/doop https://github.com/danielearwicker/doop
- danielearwicker 10y agoThe example you give has been supported since day 1. Example: document.createElement("canvas") returns HTMLCanvasElement. A limited form of string literal types has always been supported specifically for overloading return types. The newer support added in 1.8 is a way more powerful generalisation.
- nidu 10y agoIt could also benefit from constant propagation (iirc the term) where you could write obj.get(Item.name) and both get type check and stay refactoring friendly (though with cost of some more typing).