Conditional type distribution unexpected result
Quick summary
Your conditional type is distributive over a union — it evaluates separately for each member, producing a union of results.
Why this happens
The conditional type operates on a naked type parameter that is a union, triggering distribution
You expected the conditional to evaluate the union as a whole but it distributed over each member
The distribution produces a union type that is wider than the expected single type
Minimal example
type ToArray<T> = T extends any ? T[] : never;
type Result = ToArray<string | number>; // string[] | number[], not (string | number)[]type ToArrayNonDist<T> = [T] extends [any] ? T[] : never;
type Result = ToArrayNonDist<string | number>; // (string | number)[]Wrapping T in [T] prevents the conditional type from distributing over the union, giving a single array type instead of a union of arrays.
How to diagnose
Hover over the type alias usage to see the fully expanded distributed result
Wrap the type parameter in a tuple [T] to prevent distribution and see the non-distributed result
Test the conditional type with a union input and a single type input to understand the distribution behavior
How to fix
Wrap the type parameter in a tuple to prevent distribution: type NonDist<T> = [T] extends [Condition] ? A : B
Use an intersection type instead of a union if you want the conditional to apply to the combined type
Redesign the conditional type to explicitly handle union members if distribution is the desired behavior
How to prevent
Understand that conditional types distribute over naked type parameters — use [T] wrapping to prevent it
Test conditional types with both union and non-union inputs to verify the expected behavior
Related Resources
Related Glossary
Related Lessons
- Conditional Types
Learn about conditional types.