0Pricing
TypeScript Academy · Lesson

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

  1. Generic interfaces & type aliases
  2. Conditional Types (intro) & distribution over unions
  3. Reusable patterns for data models
← Back to TypeScript Academy