0Pricing
TypeScript Academy · Lesson

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>; // false

All lessons in this course

  1. keyof and Indexed Access Types
  2. Generic Constraints: Narrowing Type Parameters
  3. Conditional Types: T extends U ? X : Y
  4. Distributive Conditional Types
← Back to TypeScript Academy