ReviewOS

home-lang/home

fix(ts): contextually type nested callbacks in Zod processors

#589
Closed chris opened this 9 days ago ·
9 days ago

Parent: #548

After #588, the untouched pinned Zod 4.5.2 production corpus retains nine false TS7006 diagnostics in src/v4/core/json-schema-processors.ts. They are all nested callbacks whose containing expressions have known library or array types:

  • two Array.prototype.every predicates at lines 168-169
  • one Array.prototype.map callback at line 245
  • four Array.prototype.map callbacks at lines 373 and 416
  • two JSON.stringify replacer parameters at line 558

Pinned tsc 6.0.3 and tsgo 7.0.2 remain silent on the unchanged strict NodeNext corpus.

Acceptance criteria:

  • identify the real contextual-typing gap for these nested callbacks
  • add minimal reference-validated regression coverage
  • remove only semantically false diagnostics, with zero added diagnostics on the untouched 106-file corpus
  • measure deterministic before/after diagnostic sets
  • do not publish a timing or README row until the corpus is semantically admissible
9 days ago

First small chunk landed on origin/main: 90a9f5a (fix(ts): model complete array callback parameters (#589)).

The built-in Array model now matches the full lib callback parameter lists: (value, index, array) for map/every/filter/etc. and (accumulator, value, index, array) for reduce/reduceRight. Focused strict regressions verify both contextual types and the absence of the prior false TS2345; the full ts_checker suite, zig fmt --check, scoped Pickier, and git diff --check pass.

Untouched pinned Zod corpus: 1,166 -> 1,164 diagnostics, exactly 2 false diagnostics removed and 0 added, byte-identical across two runs (SHA-256 05b677ab53676ffdf922f486701060d54ab9ff8dc5da04230bafe8027d75b3eb). One removal is the directly explained full-arity .map TS2345 in classic/from-json-schema.ts; the other is a false TS2430. The nine target TS7006 diagnostics remain, so this issue stays open.

Two broader approaches were explicitly rejected before landing this chunk: richer JSON overload allocation produced one added false TS2430, and globally publishing qualified interface graphs produced two added false diagnostics. Neither was committed. This keeps the zero-addition benchmark gate intact.

9 days ago

Second #589 chunk landed on origin/main: aa659e5 (fix(ts): contextually type JSON transform callbacks (#589)).

Home now supplies the standard (key: string, value: any) context for built-in JSON.parse revivers and JSON.stringify replacers without changing the permissive lightweight overload surface. The implementation verifies the receiver is the cached built-in JSON object; a focused shadowed-JSON control continues to emit both expected TS7006 diagnostics.

Validation:

  • focused built-in and shadowing regressions pass
  • full ts_checker suite passes
  • zig fmt --check, scoped Pickier, and git diff --check pass
  • untouched pinned Zod corpus: 1,164 -> 1,162 diagnostics
  • exact delta: the two intended json-schema-processors.ts:558 TS7006 diagnostics removed, 0 added
  • two optimized runs byte-identical, SHA-256 fcfb4df6c0f270edc09a9a6287be10eb0b4c1690df1ce0d198fb63089b24bd4a

Seven nested array-callback TS7006 diagnostics remain, so #589 stays open.

9 days ago

Further root-cause work isolated the remaining imported-return case to Readonly<Record<string, EnumValue>>. An exact mapped-schema experiment passed ts_program but crashed the untouched Zod run with exit 139 and introduced a false reduction TS2345, so it was rejected and fully reverted; the empty crash output is not counted. The unsafe mapped-utility transfer path is now tracked in #591. Worktree and origin/main remain clean at aa659e5.

9 days ago

Safety update: 67adab666 on origin/main fully reverts the unsafe transferred utility/qualified-reference experiment tracked by #591. The admitted untouched Zod baseline is restored and deterministic at 1,162 diagnostics across two byte-identical ReleaseFast runs (SHA-256 0d1d85991dcbb73deb00dba10da1bbef60c10c48fd50b3819887096553110ab9). The seven target array-callback TS7006 diagnostics remain, so this issue stays open and no timing/README claim is being published from the rejected experiment.

9 days ago

Correction: the reported 1,162 -> 1,821 comparison was invalid because 82 generated .js files had contaminated the pinned src/v4 tree and changed NodeNext resolution. Those files are quarantined, the source tree matches the official Zod 4.5.2 tarball byte-for-byte, and an explicit --noEmit run restores the admitted 1,162-diagnostic baseline (SHA-256 0d1d85991dcbb73deb00dba10da1bbef60c10c48fd50b3819887096553110ab9). The utility experiment remains removed pending a clean retest; the seven target diagnostics still define this issue.

9 days ago

#609 now has a safe foundation on origin/main: 0bd698363 retains fully transferable scalar namespace aliases inside exported interfaces, with exact cross-file array callback context in the focused reduction and a zero-change Zod corpus gate (1,162 diagnostics, 0 added/0 removed, two byte-identical --noEmit runs). Rich structured and mapped projections remain deliberately unsupported, so the seven target Zod callbacks are unchanged and #589 stays open.

9 days ago

#591 landed an independently valid safety prerequisite as 6c4c9be01: object-literal mismatch checking now snapshots interner members before nested checks can relocate the pool. Full checker tests pass and the clean Zod gate remains exactly 1,162 diagnostics (0 added/0 removed, baseline-identical hash twice). A compact Readonly<Record<...>> candidate did remove the two target .every TS7006s, but also added 156 processor TS7006s and two false TS2430s, so it was fully rejected. Seven target diagnostics therefore remain.

9 days ago

Progress landed on origin/main via d8fc967a9 and 23a559690; child issue #591 is complete.

The readonly Record transfer removes the two target .every TS7006 diagnostics at json-schema-processors.ts:168-169. Together with the previously admitted JSON callback work, the #589 target set is now down from nine false TS7006 diagnostics to five. The same change also removes two false callbacks in schemas.ts:3516,3520, two false impossible-comparison diagnostics, two false generic-interface diagnostics, and one downstream false assignment.

Untouched Zod gate: 1,162 → 1,153 diagnostics, 0 added / 9 removed, two byte-identical runs at SHA-256 265739efe928fd81e15df0d5a7012cc8bb1aabe6d355903760b227559ede451e, explicit --noEmit, and zero generated JavaScript files. Full checker/program suites pass, and both focused reductions are accepted by version-verified TypeScript 6.0.3, native TypeScript 7.0.2, and Home.

#589 remains open for the five remaining processor callback diagnostics; no timing or README benchmark row is admitted from this correctness-only result.

9 days ago

Progress landed on origin/main in 2fdb7d0c9 (fix(ts): project qualified assertion array members (#609)).

On the admitted Zod 4.5.2 corpus this removes 4 more nested callback TS7006 diagnostics with 0 added diagnostics (1,153 -> 1,149): both x and i callbacks at json-schema-processors.ts lines 373 and 416. Two runs were byte-identical (9a171804efa705d3c9cc15053c5b6b02e87704b415af3c638b1e6e9ef3c27145) and emitted no JS.

One target callback remains: m in mime.map at line 245, tracked under #609.

9 days ago

Completed by a5ae69070 on origin/main (fix(ts): project indexed assertion array bindings (#609)).

The last target callback, m in mime.map at json-schema-processors.ts:245, now receives contextual typing. The admitted Zod corpus moves from 1,149 to 1,148 diagnostics with 0 added / 1 removed; two runs are byte-identical (a9747a7f3a4f28de0fc3737b17fd3af2cad83a72ff6fed03ed2aff4c11734b4a) and emit no JS.

Together with the earlier #591 and #609 commits, every nested-callback target tracked by this issue is resolved.

Sign in to comment on this issue.