Discriminated Unions | Typescript
You can combine singleton types, union types, type guards, and type aliases to build an advanced pattern called discriminated unions, also known as tagged unions or algebraic data types.
The kind property is called the discriminant or tag.
Now let's use the discriminated union:
Exhaustiveness checking#
We would like the compiler to tell us when we don't cover all variants of the discriminated union.
Use the never type that the compiler uses to check for exhaustiveness: