Introduction
Union types let you say a value can be one of several types. This helps your code accept different kinds of data safely.
When a function can accept more than one type of input, like a number or a string.
When a variable might hold different types at different times.
When you want to be clear about all possible types a value can have.
When you want to avoid errors by checking types before using values.