LESSON 1.2

Unions and narrowing

10:20·20,968 learners
Daniel OkaforDaniel Okafor
Next lesson

In this lesson you will

  • Model alternatives as a discriminated union
  • Narrow with typeof, in, and discriminant checks
  • Make a switch exhaustive with a never assertion

A discriminated union plus a check on the discriminant is the workhorse pattern of typed application code. Narrowing is how the compiler follows your control flow.

What this lesson covers

  • Model alternatives as a discriminated union
  • Narrow with typeof, in, and discriminant checks
  • Make a switch exhaustive with a never assertion

This lesson sits in How the Type System Thinks, part of TypeScript for Application Developers. It assumes what came before it and leads directly into the next lesson in the module.

PRO TIP

An exhaustive switch that assigns the leftover case to never turns a future missing branch into a compile error.

UP NEXT

1.3 · Literal types and const assertions

05:38

TypeScript for Application Developers

8%

Every lesson, searchable to the second.

© 2026 BIBLION

PRIVACY · TERMS · CONTACT