Menu

Unions, Intersections, and Narrowing

Module 5: Unions, Intersections, and Narrowing

Introduction

Real values are often "one of several things": a payment is UPI, card, or cash on delivery; an API call either succeeds or fails; an order is pending, shipped, or cancelled. Union types describe these choices, and narrowing is how you safely work out which choice you have.

This module covers union and intersection types, the ways TypeScript narrows a type based on your checks, discriminated unions for modelling state, and custom type guards for checks TypeScript cannot work out by itself.

What you will learn in this module

  • How union (|) and intersection (&) types differ
  • How typeof, truthiness, equality, in, and instanceof narrow types
  • How discriminated unions model state and enable exhaustive checks
  • How to write type predicates and assertion functions

TypeScript Tutorial

J

Jebasta





Get in Touch For Details