Type narrowing is how TypeScript refines a broad type into something more specific inside a code block. Every time you write an if check, a typeof guard, or a discriminated union switch, you're narrowing.
This page covers the key narrowing techniques. For the full reference with examples of each pattern, see the type narrowing cheat sheet.
What You'll Practice: TypeScript Type Narrowing: Guards, Predicates & Patterns
Narrow with typeof, instanceof, and the in operatorWrite type guard functions with x is T return typesUse discriminated unions for exhaustive branchingApply exhaustive checking with neverAvoid narrowing pitfalls with closures and mutability
TypeScript Type Narrowing: Guards, Predicates & Patterns Sample Exercises
Example 1Difficulty: 1/5
Inside the if block, what is the type of x?
stringExample 2Difficulty: 1/5
Inside the if block, is name definitely a string or could it still be null?
stringExample 3Difficulty: 2/5
What operator checks if a property exists on an object for type narrowing?
in+ 2 more exercises
Quick Reference
TypeScript Type Narrowing: Guards, Predicates & Patterns Cheat Sheet →Copy-ready syntax examples for quick lookup