That runs counter to one of the goals of TypeScript, which is to make no runtime changes.
It’s easy enough to do this in userland. I wrote a tiny library called narrows which has worked great for me: https://www.npmjs.com/package/narrows
It’s easy enough to do this in userland. I wrote a tiny library called narrows which has worked great for me: https://www.npmjs.com/package/narrows
After I looked at it, I have a sour feeling in my mouth. Why there can't be a way (or a library) to do very easy type guards in TypeScript? Something as simple as the keyword `is` in C#
I’ll add that writing manual type guards is fairly infrequent, so in practice there’s not a lot to gain here.
*Modulo polyfilling newer ES features if you compile for a lower version of the spec.