Skip to content

TypeScript `OptionalChain` Narrowing in 2026: Why `?.` Does Not Always Narrow the Way You Think It Does

7.8 relevance
Score Breakdown
technical depth
9
novelty
8
actionability
8
community
6
strategic
5
personal
8

Scored daily by a customisable AI persona to surface the most relevant engineering leadership news.

Advanced TypeScript type narrowing edge case, highly actionable for TypeScript developers.

AI/ML dev.to
TypeScript `OptionalChain` Narrowing in 2026: Why `?.` Does Not Always Narrow the Way You Think It Does
Summary

TypeScript's optional chaining (`?.`) short-circuits at runtime on `null` or `undefined` but does not narrow the base union type in the type system, leaving `T | undefined` intact inside conditionals. This breaks type safety in property length checks and discriminated unions, forcing developers to combine `?.` with explicit null checks, the `in` operator, or type predicates to restore correct narrowing. The behavior, unchanged since TypeScript 3.7, stems from the compiler lacking discrete control flow points when the entire expression collapses into a single operation.

Author

jsmanifest

More from jsmanifest →