Conditional Types (intro) & distribution over unions
Learn conditional types (T extends U ? X : Y) and how they distribute over unions for powerful type-level logic.
Intro
Goal: Use conditional types (T extends U ? X : Y) to branch at the type level, and understand distribution over unions for precise results.
Basic conditional
A conditional type returns one of two types based on whether T extends U holds.
type IsString<T> = T extends string ? true : false;
let a: IsString<string>; // true
let b: IsString<number>; // false
All lessons in this course
- Generic interfaces & type aliases
- Conditional Types (intro) & distribution over unions
- Reusable patterns for data models