TypeScript · Types and shapes

Literal type

Restricts a value to exact literals. Perfect for options, states and event names.

Syntax
type Direction = "up" | "down"

Example

Example
type Direction = "up" | "down" | "left" | "right";
const move: Direction = "up";

More in this group

any Array types enums Function type Interface never null and undefined Optional property

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course