Extract<T, U>

Constructs a type by extracting from T all union members assignable to U.

Since TS 2.8 Spec ↗

Syntax

Extract<Type, Union>

Returns

union type — The union of T members that are assignable to U.

Examples

type T = 'a' | 'b' | 'c';
type Result = Extract<T, 'a' | 'z'>; // 'a'
type Fns = Extract<string | (() => void) | number, Function>;
// () => void

Notes

Defined as the distributive conditional `T extends U ? T : never`. It is the complement of `Exclude`. Commonly used to narrow a discriminated union to the members matching a given shape.

See also