Union type ( | )
Try it yourself →A variable being able to take multiple types.
Syntax
let x: type1 | type2;
Description
With | (or), you state that a variable can be one of several types.
Example
let identity: number | string; identity = 42; console.log(identity); identity = "A42"; console.log(identity);
Expected output
42 A42
When to use?
Fields that can be both numbers and strings (id, input value).