Files
scriptc/tests
Malte Ubl 4831665524 Restore present arms of stale narrowings in typed slots
An assignment narrows a binding to the assigned arm, and TypeScript keeps
that narrowing across a closure or method that stores another arm. After
`if (acc !== null) return acc;` the checker still types the read as the
old arm, the return slot rejects the declared `T | null`, and the checked
extraction threw on the value the closure stored, where Node returns it.
The compiler itself has this shape (lowerDynObjectLiteral), so the native
compiler aborted with "a value of another type is not representable in
the target union" and closure-nullable-union-return.ts diverged.

A slot that accepts the declared type minus null/undefined now reads the
stale reference as NonNullable<declared>, like a binding narrowed only by
the absence test. Elements and properties of array and object literals
are such slots when the literal itself sits in a typed slot (annotated
declaration, argument, assignment, return of a function with a declared
return type). Untyped literals keep the checked extraction.
2026-10-11 06:39:39 -07:00
..
2026-07-22 18:08:04 -05:00
2026-10-10 10:08:39 -05:00