RSRobince Studio

TypeScript Union Types

A union type lets a value be one of several types, written with a vertical bar. You can also union specific literal values, which is great for a fixed set of options.

let id: number | string = 42
id = "A42" // also allowed

let size: "small" | "large" = "small"
Try it yourself

Loading editor…