4 ms·
That proposal is really dragging though. And typescript needs as much work because that's where the real power is. We need discern thing like match (x) {
by ibejoeb 11mo ago
That proposal is really dragging though. And typescript needs as much work because that's where the real power is. We need discern thing like
match (x) {
"bob": ...,
string: ...,
() => Promise<void>: ...,
() => Promise<string>: ...,
}
with exhaustiveness checking for it to be truly useful.
- ameliaquining 11mo agoDiscriminating a function or promise based on return type is never going to work, because JavaScript is dynamically typed and TypeScript erases types at compile time, so there's no way to know at runtime what type a function or promise is going to return.
- ibejoeb 11mo agoIt'll work because that's what typescript does, and that's why it needs to be implemented there, also. That's my point. And as far as runtime goes, well, that's not what typescript does. It's a typical compile-time static type system. Typescript aside, even a javascript-level first-class pattern expression is still extremely useful. I really hope it gets in there soon.