0Pricing
TypeScript Academy · Lesson

Distributive Conditional Types

Control how conditionals distribute over unions.

A Surprising Behavior

Conditional types have one special rule: when the checked type is a naked type parameter and you pass a union, the conditional distributes over each member separately, then unions the results.

This is the foundation of Exclude, Extract, and many utilities.

type ToArray<T> = T extends unknown ? T[] : never;

type A = ToArray<string | number>;
// string[] | number[]  (NOT (string | number)[])

What "Naked" Means

"Naked" means the type parameter appears by itself on the left of extends, not wrapped in another type. Distribution only happens for naked parameters.

type Naked<T> = T extends string ? "y" : "n";
// T is naked -> distributes over unions

All lessons in this course

  1. Types as a Computation Language
  2. Type-Level Conditionals
  3. Type-Level Recursion
  4. Distributive Conditional Types
← Back to TypeScript Academy