ReviewOS

home-lang/home

fix(ts): remove impossible union branches after property narrowing

#672
Closed chris opened this 8 days ago ·
8 days ago

Parent

  • #548 TypeScript correctness
  • #416 TypeScript performance

Problem

After #671, the pinned Zod 4.5.2 corpus has 374 diagnostics / 369 unique identities. Ten remaining TS7006 identities in locale files share an array-property flow shape.

A fair same-file reduction shows the core fault without Zod names or imports:

type Primitive = string | number | null | undefined;
interface A { options?: Primitive[] }
interface B { options?: never }
declare const issue: A | B;

if (issue.options) {
  issue.options.map((value) => value);
}

TypeScript 6.0.3 and the native preview accept this. ReleaseFast Home incorrectly retains never | Primitive[], reports TS2339 on .map, and then TS7006 on value. The stronger Array.isArray(issue.options) && issue.options.length > 0 form also reports false TS2339 for both length and map, loses the callback type, and misses the intended invalid-use diagnostics.

Requirements

  • Remove impossible never branches through normal union/flow semantics after truthy property narrowing.
  • Preserve the declared array element type and normal array members; do not special-case options, map, locales, or Zod.
  • Do not add a depth cap, diagnostic suppression, source-text heuristic, or widening workaround.
  • Add focused checker coverage for the minimal truthy union and a strict invalid-control oracle covering the Array.isArray chain.
  • Require exact TypeScript 6/native/Home diagnostic-code parity on the invalid control, full checker and Program suites, ReleaseFast, formatting/diff checks, and the repository Pickier baseline.
  • Run the pinned 106-file Zod 4.5.2 graph twice against the exact #671 parent and reject any added diagnostic identity.
  • Document accepted/rejected evidence in docs/docs/TS_PERFORMANCE.md and summarize it in the README table.
8 days ago

Implementation evidence for 673a648a9 (pushed directly to origin/main):

  • Stable member truthiness now uses the checker's existing semantic truthy partition instead of only removing null/undefined. This removes impossible never constituents while retaining representable broad primitive types; there is no member-name/library/source special case.
  • Exact strict oracle: TypeScript 6.0.3, native TypeScript preview, and ReleaseFast Home each report exactly one intentional TS2322. Home no longer reports false TS2339 on length/map or TS7006 on the callback.
  • Focused permanent checker regression: passed.
  • Complete checker suite: passed.
  • Complete Program suite: 201/201 passed.
  • ReleaseFast build, zig fmt --check, and git diff --check: passed.
  • Pinned 106-file Zod 4.5.2, twice: byte-identical to the exact #671 parent at 374 diagnostics / 369 unique identities. Zero removed and zero added. Raw stderr SHA-256 remains 5353246e2b9172390011adff013f5807c60da3019b28e34f3d814e50d80fcf80.
  • Repository-wide bunx --bun pickier .: unchanged baseline failure, 22,427 findings (11,834 errors, 10,593 warnings).

The unchanged Zod result disproves the initial hypothesis that this impossible-branch bug caused the 10 locale TS7006 reports. I will document that negative result and isolate the locale family separately.

8 days ago

Completed and documented on origin/main:

  • 673a648a9 — fix(ts): remove impossible truthy property branches (#672)
  • 307892be9 — docs(ts): publish truthy property audit (#672)

The focused semantic bug is fixed with exact TS6/native/Home parity and all gates passing. The frozen Zod A/B is byte-identical to #671 at 374 diagnostics / 369 unique identities, with zero additions; the docs explicitly retain this negative production result rather than claiming a corpus improvement.

Sign in to comment on this issue.