union type

A type that allows one of several listed types or values, written with a vertical bar, such as int | None in Python or "small" | "large" in TypeScript.

In more detail

Think of each type as a set of values: a union is the combined set. Without narrowing you may only use what every member supports, so a type checker insists you handle the None case before using an int | None value as a number. Python hints accept the bar syntax from Python 3.10; older code writes Optional[int] or Union[int, None].

Examples

Variant props are unions of their allowed options, which is how VariantProps and theme types such as "light" | "dark" are typed.
type Bump = "patch" | "minor" | "major" in the governance lesson.
def find_user(name: str) -> str | None: ...
type QueryParam = string | string[] | number | null | undefined;

Related terms

Taught in

References