Exclude<T, U> loại bỏ khỏi union T những types có thể assign cho U: Exclude<'a'|'b'|'c', 'a'> cho ra 'b'|'c'. Extract<T, U> ngược lại — giữ lại những types assign được cho U: Extract<string|number|boolean, string|number> cho ra string|number.
Ví dụ thực tế: type NonString<T> = Exclude<T, string> để lọc string ra khỏi union.
Exclude<T, U> removes from union T the types assignable to U: Exclude<'a'|'b'|'c', 'a'> gives 'b'|'c'. Extract<T, U> is the opposite — keeps the types assignable to U: Extract<string|number|boolean, string|number> gives string|number.
- Practical example:
type NonString<T> = Exclude<T, string>to filter strings from a union. - Memory tip: Exclude = remove, Extract = keep the intersection.
NonNullable<T>is built on:Exclude<T, null | undefined>.