Extract types from a union that are assignable to another type.
The Extract utility type constructs a type by keeping only the members of union type T that are assignable to type U. It is the opposite of Exclude and acts as a type-level filter that retains matching members.
Extract is useful when working with discriminated unions to pull out specific variants, or when you need to find the common types between two unions.
Like Exclude, Extract uses distributive conditional types. Each member of the union T is independently checked against U, and only members that extend U are kept in the result.
type T = Extract<'a' | 'b' | 'c', 'a' | 'c'>;
// 'a' | 'c'
type NumericTypes = Extract<string | number | boolean | bigint, number | bigint>;
// number | bigint