Literal type
Allows only specific values.
Syntax
let x: "a" | "b" | "c";
Description
Specifies that the variable can only take listed values (fixed options).
Example
Loading editor…
Expected output
left
When to use?
Fixed options (status, direction, size) — prevents invalid values.
Common mistakes
- ⚠️ direction = "up"; → ERROR: allowed values are only "left" | "right".