by lhorie · 3y ago · 0 comments
That's not strictly true though. `a<b,c>(d)` is valid Javascript but Typescript treats it as a different syntactic construct[0].
[0] https://www.typescriptlang.org/play?#code/C4TwDgpgBARlC8UB2B...
class b {}
class c {}
const d = JSON.parse
const a = Promise.prototype.then.bind(Promise.resolve(1))
console.log(a<b,c>(d))
// TS output: Promise { <state>: "pending" }
// JS output: false false
TS playground: https://tsplay.dev/mAdeZNedit: there is indeed an edge case with the parentheses that throws the TypeScript parser off even if only values are involved.
This is different than JSX or hashbang, where the set of non-JS syntax cannot legally overlap with existing syntax/semantics.