# TypeScript Level 3: Unions & Narrowing

> Level 3: Unions & Narrowing of the LoWisa TypeScript course: Union and Intersection Types, Type Guards and Control-Flow Analysis, Discriminated Unions. 3 lessons and 9 ideas, each explained in one line.

Unions & Narrowing is level 3 of 16 of the [LoWisa TypeScript course](/courses/typescript/). It has 3 lessons and 9 ideas. Below is every lesson and what it teaches, in one line each.

## Union and Intersection Types

- **Unions.** A **union** type says one-of: string | number is a value that is either, and only common operations are allowed.
- **Intersections.** An **intersection** combines shapes: Draggable & Resizable must satisfy both contracts at once.
- **Modelling with unions.** Unions model reality: a request is "loading" | "success" | "error": three **states**, each with its own data.

## Type Guards and Control-Flow Analysis

- **typeof narrowing.** An if (typeof x === "string") **narrows** x to string inside the branch: the checker follows your logic.
- **Control-flow analysis.** The compiler tracks each branch and early return, updating a value’s type through the **flow** of the code.
- **Custom guards.** A predicate returning x is **User** teaches the checker your own runtime test: narrowing you define.

## Discriminated Unions

- **The discriminant.** Give each variant a literal **kind** property: {kind: "circle"; radius: number}: and switching on it narrows perfectly.
- **Exhaustive switches.** An **exhaustive** switch with a never-typed default makes the compiler flag every unhandled variant forever.
- **The workhorse pattern.** Discriminated unions are TypeScript’s workhorse: **events**, results, and states all model cleanly as tagged variants.

## Before and after this level

- **Before:** [Level 2: Object Types](/courses/typescript/level-2-object-types/): Interfaces and Type Aliases, Optional and Readonly Properties, Structural Typing.
- **Next:** [Level 4: Functions](/courses/typescript/level-4-functions/): Function Types and Signatures, Optional, Default and Rest Parameters, Overloads and Callback Types.

In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See [Checkpoints and flashcards](/help/checkpoints-and-flashcards/).

## Frequently asked questions

### What does TypeScript Level 3: Unions & Narrowing cover?

Union and Intersection Types, Type Guards and Control-Flow Analysis, Discriminated Unions: 3 lessons and 9 ideas.

### What should I know before this level?

The level before it, Level 2: Object Types, which covers Interfaces and Type Aliases, Optional and Readonly Properties, Structural Typing.

## Learn TypeScript on your phone

The first level is free. LoWisa is on Google Play and the App Store.

---

Source: https://lowisa.dev/courses/typescript/level-3-unions-and-narrowing/ · Updated 2026-11-16
