never in Distributive Conditionals
What you'll learn: How returning never from a conditional type branch makes that union member vanish from the final result.
The Disappearing Act
You've seen how distributive conditional types process each union member separately. Here's the magic: when a branch returns never, that branch contributes nothing to the final union. It's like filtering — any member that produces never simply disappears.
Think of it like a security checkpoint: each union member passes through individually. If the conditional returns never for a member, that member doesn't make it through to the other side.
How It Works
type RemoveStrings<T> = T extends string ? never : T;
type Result = RemoveStrings<string | number | boolean>;
// Result = number | boolean
Here's what happens step-by-step:
string extends string ? never : string→nevernumber extends string ? never : number→numberboolean extends string ? never : boolean→boolean- Union the results:
never | number | boolean→number | boolean
Since never is the empty type, unioning it with anything has no effect — it disappears.
The Filter Pattern
This is exactly how utilities like Exclude work:
type MyExclude<T, U> = T extends U ? never : T;
type Numbers = MyExclude<1 | 2 | "a" | "b", string>;
// Numbers = 1 | 2
Any member that matches the pattern gets replaced with never and vanishes.
Why This Matters
This pattern lets you build type-level filters. Want only functions from a union? Only objects? Only primitives? Return never for what you don't want, and it silently disappears from the result.
Key Takeaway: In distributive conditional types, returning never from a branch removes that union member from the final result type, enabling powerful type-level filtering.