TypeScript OptionalChain Narrowing in 2026: Why ?. Does Not Always Narrow the Way You Think It Does
This article was written with the assistance of AI, under human supervision and review.
Optional chaining returns undefined for null or undefined values, but TypeScript treats the result as the original type or undefined without narrowing the base union. This breaks type safety in conditional checks, length property tests, and discriminated unions when developers expect ?. to act as a type guard. The ?. operator checks only the left-hand value at runtime while the type system preserves the full union, forcing developers to combine optional chaining with explicit narrowing techniques like the in operator, type predicates, or separate null checks to restore correctness.
TypeScript 3.7 introduced optional chaining as a runtime convenience for accessing deeply nested properties. Developers write foo?.bar?.baz expecting both runtime safety and type narrowing.…