3 ms·
Technically typescript is a strict superset of JS, but yes
by tazard 8y ago
Technically typescript is a strict superset of JS, but yes
- lhorie 8y agoTechnically technically, it turns out that no it's not. I recently realized that `a<b>(x)`, `a<b,c>(x)` and variations mean something completely different in TS than they do in JS.
- spraak 8y agoIs that denoting generics? Can you give an example?
- alangpierce 8y agoYeah, it's the syntax when calling a generic function, e.g. `Array.of<number | null>(1, 2, null);` has return type `Array<number | null>`. You usually don't need to specify the type since TypeScript can figure it out, but sometime's it's necessary to specify it explicitly. TypeScript compiles `a<b>(x)` to `a(x)`, which is a function call, but when run as plain JS, `a<b>(x)` is a less-than and greater-than comparison between a, b, and x.
- tazard 8y agoThat's interesting and so obvious now that you mention it. Thanks for the clarification.
- chrismorgan 8y agoAnd that’s exactly why Rust has the turbofish (a :: before the <), to resolve that syntactic ambiguity. TypeScript could have resolved it by requiring a . before the <, but it didn’t, and so you can devise contrived cases like this where it differs from JavaScript.