Files
scriptc/tests
Malte UblandClaude Opus 5.5 15cc7310ac Keep record values that subtype reduction folds into an inferred type
TypeScript infers a function's return type as the subtype-reduced union of
the values it returns: returning `{ status }` in one branch and
`{ status, value }` (or a call returning either) in another infers just
`{ status }`. Records have fixed layouts, so that type cannot hold the
second value: the return failed its union wrap at run time ('... is not
representable in the target union'), and values that reached a binding of
the reduced type failed a checked narrowing.

- A function with an inferred return type and no contextual signature
  returns the union of the record types it actually returns, including
  through calls of other such functions. Only value types the checker's
  reduction dropped from the inferred union are added, so functions whose
  inferred type already names every returned type keep their layout.
  Declared return types keep their meaning.
- Reading such a union through the reduced type (a binding, a member read,
  JSON.stringify) uses a dedicated checked extraction that converts the wider
  record arms with the ordinary width coercion; other narrowings are
  unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 18:26:39 -07:00
..
2026-10-23 07:50:09 -05:00
…