4 ms·
You can use discriminated unions with TS (https://antman-does-software.com/typescripts-discriminated-unions-with-real-use-cases https://antman-does-software.com
by patates 4y ago
You can use discriminated unions with TS (https://antman-does-software.com/typescripts-discriminated-unions-with-real-use-cases https://antman-does-software.com/typescripts-discriminated-u...), and you can even parse them from unknown data using tools like zod (https://zod.dev/?id=discriminated-unions https://zod.dev/?id=discriminated-unions), io-ts, or the likes.
I can't think of anything I can do in .NET (which has runtime types) that I can't do in TS with the help of a library or two.
- sa46 4y ago> I can't do in TS with the help of a library or two. Libraries like io-ts and zod embed the type information into JavaScript, so the information is available at runtime but only for wrapped types. If TypeScript provided runtime type information, such libraries wouldn't be necessary.