Distributive Conditional Types
Understand how conditionals distribute over union members.
Distributive Conditional Types is a free TypeScript Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome
What Is Distribution
type Wrap<T> = T extends any ? { value: T } : never;
type R = Wrap<string | number>;
// = { value: string } | { value: number }The Key Condition
type Bare<T> = T extends string ? 'yes' : 'no';
type Wrapped<T> = [T] extends [string] ? 'yes' : 'no';
type B = Bare<'a' | 'b'>; // 'yes' | 'yes' = 'yes'
type W = Wrapped<'a' | 'b'>; // 'no' — treated as a tupleFiltering Unions with never
type StringsOnly<T> = T extends string ? T : never;
type S = StringsOnly<string | number | boolean>; // stringExtract Built-In
type Extract<T, U> = T extends U ? T : never;
type E = Extract<string | number | boolean, string | number>; // string | numberExclude Built-In
type Exclude<T, U> = T extends U ? never : T;
type Ex = Exclude<string | number | boolean, boolean>; // string | numberToArray Distribution
type ToArray<T> = T extends any ? T[] : never;
type R = ToArray<string | number>; // string[] | number[]Preventing Distribution Use Case
type IsUnion<T> = [T] extends [T] ? [T] extends [Exclude<T, T>] ? false : true : false;Distributive Mapped Types
type PickByValue<T, V> = {
[K in keyof T as T[K] extends V ? K : never]: T[K]
};Distributive Conditional in ReturnType
type Fn = (() => string) | (() => number);
type R = ReturnType<Fn>; // string | numberEager vs Lazy Distribution
Quick Check
Recap
Frequently asked questions
Is the “Distributive Conditional Types” lesson free?
Yes — the full text of “Distributive Conditional Types” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Distributive Conditional Types”?
Understand how conditionals distribute over union members. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Distributive Conditional Types” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- keyof and Indexed Access Types
- Generic Constraints: Narrowing Type Parameters
- Conditional Types: T extends U ? X : Y
- Distributive Conditional Types