conditional type

A type that picks one of two types depending on whether a type is assignable to another, written like a ternary expression with extends.

In more detail

It is an if statement that runs in the type checker. With infer it can pull types out of arrays, promises and functions. Many utility types, such as Exclude and ReturnType, are conditional types.

Example

type UnpackPromise<T> = T extends Promise<infer R> ? R : T;

Related terms

Taught in

References