object-transforms
Exclude<T, U>
Filters a union T by removing every member that is assignable to U. Distributes over union members via the conditional type, producing the set-difference T \ U.
type Exclude<T, U> = T extends U ? never : T Usage patterns
| Pattern | Purpose |
|---|---|
| Exclude<T, null | undefined> | Equivalent to NonNullable<T> |
| Exclude<keyof T, K> | Compute complementary key set (basis of Omit) |
| Exclude<T, Function> | Remove function members from a mixed union |
| Exclude<T, never> | Identity — returns T unchanged |
Examples
type Fruit = 'apple' | 'banana' | 'cherry';
type NotBanana = Exclude<Fruit, 'banana'>; Result: 'apple' | 'cherry'
type T = string | number | boolean;
type NonBool = Exclude<T, boolean>; Result: string | number
type Keys = Exclude<keyof User, 'password'>; Internal building block of Omit — enumerates safe keys
type X = Exclude<'a' | 'b', 'a' | 'b' | 'c'>; Result: never — every member of T is assignable to U
Gotcha
Exclude only works on union types — a plain object type passed as T will not be reduced. The distributive behavior can also over-fire on generics; wrap the parameter in a tuple `[T] extends [U]` to disable distribution.
Related utility types
Extract<T, U>
Keeps only those members of union T that are assignable to U. The dual of Exclude, giving the set-intersection T ∩ U.
NonNullable<T>
Removes null and undefined from the type T. In TS 4.9+ it is implemented as `T & {}`, which drops nullish members without altering the rest.
Omit<T, K>
Constructs a type by removing the properties in K from T. Unlike Pick, its K is not constrained to keyof T, so extra keys are silently ignored.
infer R
A keyword usable only inside the extends clause of a conditional type that introduces a fresh type variable inferred from the matched shape. It is the primitive that powers ReturnType, Parameters, InstanceType, Awaited, and countless custom utilities.
Partial<T>
Constructs a type where every property of T is set to optional. Useful for representing update payloads, patch objects, and configuration overrides where all fields may be omitted.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never