Docs
/
TypeScript
Chapter 5

05 — Union & Intersection Types

Core Concepts

  • Union Types (A | B) — value can be A or B (or both)
  • Intersection Types (A & B) — value must be both A and B
  • Narrowing — reducing a union to a specific type via checks
  • Literal Unions — specific values as types ("a" | "b" | "c")
  • Discriminated Unions — unions with a shared kind/type field for safe narrowing
  • Distributive Behavior — how unions interact with generics and conditionals

Union vs Intersection

FeatureUnion (A | B)Intersection (A & B)
MeaningA or BA and B
Properties accessibleOnly shared onesAll from both
Use caseMultiple possible typesCombining types
Narrowing neededYesNo