Union types let us tell TypeScript a value can be of one type, or another type.
Example:
const run = (a: number | string) => {
//...
}
In this case the parameter a
can be either a string, or a number, but nothing else.
Union types let us tell TypeScript a value can be of one type, or another type.
Example:
const run = (a: number | string) => {
//...
}
In this case the parameter a
can be either a string, or a number, but nothing else.