4 ms·
It is the way I always wanted to use JavaScript, but was too cumbersome to utilise without a good type system. My favourite use-case for discriminated unions i
by JoeyJoJoJr 4y ago
It is the way I always wanted to use JavaScript, but was too cumbersome to utilise without a good type system.
My favourite use-case for discriminated unions is to represent all possible client events as a DU, as well as the entirety of the application state. This allows you to efficiently communicate with a backend over websockets via a very thin transport layer that only needs to handle one message type.