Hacker News new | ask | show | jobs
by dsirola 1924 days ago
I don't think that's possible since types are not present at the runtime. They are just stripped away during compilation
1 comments

It would still be possible as long as all the necessary information is available at compile time.
Dispatch during pattern matching happens at runtime, which requires some means of discriminating the matched values with run-time information. Typescript doesn't provide any more runtime type information than Javascript does, and so it can't see the difference between "Object" and "Object" unless the object has fields that allow it to, such as the class constructor or programmer-specified values. I don't think that the compiler adding additional information to discriminate types other than what JS already provides fits with the design goals of Typescript being a language that only adds static typing.