Re:TypeScript 3.5
by tomp on Thursday May 30, 2019 @02:02AM
(#20048783)
Probably... but in any case TypeScript also supports naked (edit: I just made up the name) unions, where you don't need to declare them upfront, and where values of different types can be included directly. Such as:
TypeScript infers type
[ Parent
| on HN ]
This is still a discriminated union, only that the discriminator is provided by Javascript and is thus hidden: it's `typeof`.
Yeah, that's the runtime perspective... but for the type system, they're different... with the "naked" union being much harder (as they're non-algebraic - `a | b | b` always equals `a | b` and might even equal just `a` for some values of `a` and `b`)