4 ms·
This is still a discriminated union, only that the discriminator is provided by Javascript and is thus hidden: it's `typeof`.
by marton78 7y ago
This is still a discriminated union, only that the discriminator is provided by Javascript and is thus hidden: it's `typeof`.
- tomp 7y agoYeah, 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`)
- spion 7y agoNo, this works on any overlapping types too - even unsound combinations such as `T | Array<T>`