JavaScript & TypeScript

Type Narrowing

/taɪp ˈnærəʊɪŋ/

Definition

TypeScript's ability to refine a variable's type within a conditional block based on type guards or checks.

Example in context

"After if (typeof val === 'string'), TypeScript knows val is a string — no cast needed."

Related terms

Practice this term

Master Type Narrowing in context by working through exercises in the JavaScript & TypeScript module. You'll see the term used in real engineering scenarios with multiple-choice, fill-in-the-blank, and matching drills.