4 ms·
I don't think that's possible since types are not present at the runtime. They are just stripped away during compilation
by dsirola 6y ago
I don't think that's possible since types are not present at the runtime. They are just stripped away during compilation
- alpaca128 6y agoIt would still be possible as long as all the necessary information is available at compile time.
- flqn 6y agoDispatch 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.