never as the Empty Type in Conditionals
You'll learn: How never represents impossible branches in conditional types and acts as the identity element in unions.
The Core Idea
In conditional types, never serves as the empty type — a type with no values. When TypeScript evaluates a conditional like T extends U ? A : B, if the "else" branch (B) is never, it signals "this case is impossible" or "filter this out."
Think of never like the number zero in multiplication: just as anything × 0 = 0, when never appears in a union, it disappears: string | never simplifies to just string. This makes never the identity element for union types.
Why This Matters in Conditionals
When building utility types, you often want to filter out certain members from a union. By returning never in the "reject" branch, those types vanish from the result:
type OnlyStrings<T> = T extends string ? T : never;
// Distributed over union members:
type Result = OnlyStrings<string | number | boolean>;
// Result: string
// number and boolean get mapped to never, which disappears
The Identity Element Property
never in a union gets eliminated automatically:
type Example1 = string | never; // → string
type Example2 = number | never | void; // → number | void
type Example3 = never | never | never; // → never
This is why conditional types that return never for unwanted branches effectively filter the union — the unwanted types become never, then union resolution removes them.
Practical Filtering Pattern
// Extract only function types from a union
type ExtractFunctions<T> = T extends (...args: any[]) => any ? T : never;
type Mixed = string | ((x: number) => void) | boolean | (() => string);
type OnlyFns = ExtractFunctions<Mixed>;
// OnlyFns: ((x: number) => void) | (() => string)
Key Takeaway: In conditional types, never represents impossible branches and disappears from unions, making it perfect for filtering unwanted types from union members.