3 ms·
Frankly, use of "typeof" to tell between explicitly named types baffled me a bit. I hope they'll introduce pattern matching on type some time later.
by nine_k 12y ago
Frankly, use of "typeof" to tell between explicitly named types baffled me a bit. I hope they'll introduce pattern matching on type some time later.
- spion 12y agoThe proposed syntax is function f(val:any): val is SomeType { do checking and return boolean } and will be most likely available in 1.5.
- WorldMaker 12y agoThere's plenty of discussion on this very topic in GitHub issues and PRs. The current "typeof" is inherited from JS and TS compiler doesn't actually do much to change that code. It would be great to see a nice pattern matching syntax, but people will have to figure out what the JS that pattern matching code would look like.
- Arnavion 12y agoThe discussion on Github for user-defined type guards (spion's comment) is at https://github.com/Microsoft/TypeScript/issues/1007 https://github.com/Microsoft/TypeScript/issues/1007 Advanced pattern matching, monads, etc. might be out of scope for TS, since it doesn't want to have major syntactical additions from regular JS.