You can use discriminated unions with TS (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), 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.