Conditional Types: T extends U ? X : Y
Write type-level if statements with conditional types.
Welcome
Conditional types let you express type-level if statements. They are a core part of TypeScript's advanced type system used to build utility types.
Basic Syntax
Write T extends U ? X : Y. If T is assignable to U, the result is X; otherwise Y.
type IsString<T> = T extends string ? true : false;
type A = IsString<string>; // true
type B = IsString<number>; // falseAll lessons in this course
- keyof and Indexed Access Types
- Generic Constraints: Narrowing Type Parameters
- Conditional Types: T extends U ? X : Y
- Distributive Conditional Types