Union Types
Union types represent values that may be one of several alternatives.
Example
type Id = Number | StringWhen to use unions
- optional-like domain values
- parser outputs before narrowing
- tagged union variant groups
How unions become useful
Unions are usually paired with:
ifchecksmatch- tagged discriminants
Those tools narrow the active case so the rest of the code can stay precise.