Union Types: A or B
Use | to allow multiple type possibilities.
Welcome
Union types allow a value to be one of several types. They are written with the `|` operator and are fundamental to modeling real-world data.
Basic Union Syntax
Combine two or more types with `|`. A variable with a union type can hold any one of the listed types.
let id: string | number;
id = 'abc123'; // OK
id = 42; // OK
// id = true; // Error