Type narrowing
Type narrowing is the compile-time refinement of a value's possible static types based on control-flow checks, type guards, or equivalent analysis.
Essential TypeScript 5, Third Edition
Type narrowing is the compile-time process of restricting an expression's possible types to a more specific type.
- How it is used
- Uses assertions and guards to select usable members from union-typed values.
- How deep it goes
- Explains assertions, property checks, and instanceof guards with code, but stops short of broader control-flow narrowing rules.
- Examples
- Demonstrates tax formatting, mixed Person and Employee arrays, constructor-function shapes, and Person-or-Product collections.
- What you can do after
- Apply it via TypeScript assertions and guards to access members specific to a selected union type.
Read how Essential TypeScript 5, Third Edition explains type narrowing →
Acing the Frontend Interview
Type narrowing is the refinement of a value's static type within a control-flow branch based on runtime checks or other type guards.
- How it is used
- Applies runtime checks and control-flow reasoning to maintain type safety across diverse TypeScript codebases and interview scenarios.
- How deep it goes
- Progresses from typeof and instanceof to custom guards, discriminated unions, exhaustive checks, and never.
- Examples
- Uses typeof, instanceof, user-defined guards, discriminated unions, exhaustive checks, and never as progression examples.
- What you can do after
- Diagnose and implement safer TypeScript branches, guards, unions, and exhaustive API checks.
Read how Acing the Frontend Interview explains type narrowing →
Also covered in
- Secrets of the JavaScript Ninja, Third EditionIn early access (MEAP)
What to know first
- any typeThe any type is a TypeScript type that permits values to be treated as having essentially any type, largely disabling static type checking for them.
Related concepts
- TypeScriptused by · TypeScript is a statically typed superset of JavaScript that adds type-system features and is compiled to JavaScript.
- instanceof operatorused by · The instanceof operator tests whether an object or reference is compatible with a specified runtime type or constructor according to the programming language’s rules.
- type assertionused by · A type assertion is a language construct that states or checks that a value has a specified type, with runtime behavior depending on the language.
- type guardproduced by · A type guard is a runtime-checkable condition that enables TypeScript to narrow an expression to a more specific type within a code path.
- type predicateused by · A type predicate is a TypeScript function return-type annotation that asserts a parameter has a specified type when the function returns true.
Questions about type narrowing
What is type narrowing?
Type narrowing is the compile-time refinement of a value's possible static types based on control-flow checks, type guards, or equivalent analysis.
Which Manning books explain type narrowing?
Essential TypeScript 5, Third Edition and Acing the Frontend Interview.
What should I know before learning type narrowing?
Manning books that teach type narrowing usually introduce any type first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

