ReviewOS

home-lang/home

fix(ts): resolve mapped visitor handlers on the full Zod core graph

#821
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Parent: #548. Related: #668 (the imported Extract and mapped-handler transfer fix already landed and closed).

Reproducible gap

The unchanged pinned Zod 4.5.2 21-file core proxy still has a Home-only core/visit.ts:34:21 TS2571: Object is of type 'unknown'. at:

const h = (fnOrHandlers as VisitHandlers)[node._zod.def.type] as
  | ((n: AnyZod, rewritten: boolean) => AnyZod)
  | undefined;

Here VisitHandlers = { [K in Kind]?: (node: SchemaOfKind<K>, rewritten: boolean) => AnyZod }, with SchemaOfKind<K> using Extract over Zod's $ZodTypes union. TypeScript 6.0.3 and native TypeScript 7.0.2 do not report TS2571. The proxy's shared TS2307 for omitted locales is unrelated.

A strict two-kind, two-file reproduction of the same Extract + optional mapped handler + assertion + computed key was run under both TypeScript controls and Home. All three accept the handler expression and report only TS2322 for a deliberately wrong VisitFn return. Therefore importing the alias or using this syntax alone is not sufficient to reproduce the remaining failure; the larger Zod type graph or its instantiation/transfer path matters. Do not re-open #668 as a presumed cause without evidence.

Acceptance

  • Minimize the full-graph trigger while retaining a positive handler lookup and negative controls for an invalid handler/return or key.
  • Fix the general type-evaluation or transfer cause so the frozen core proxy loses core/visit.ts:34:21 TS2571 with zero new exact diagnostic identities; preserve both controls' behavior.
  • Add focused checker and Program regressions, run full relevant suites and a guarded optimized home-tsc build, document the exact normalized before/after set, and link the checkpoint to #548.
  • Keep the full 106-file Zod graph and benchmark timing gated on separate complete admission.

No source-name special cases, unknown/any casts inserted in the corpus, suppressed diagnostics, skips, or fixture edits.

9 days ago

Resolved on main by f18ef91.

Verified result:

  • Frozen unchanged 21-file Zod 4.5.2 core proxy: 2 -> 1 exact diagnostic identities, removing core/visit.ts:34:21 TS2571 with 0 added. The sole remaining TS2307 at core/index.ts:11:26 is the shared omitted-locales proxy boundary reported by both controls.
  • Generic two-file oracle with an opaque imported type and three defaulted parameters: Home, TypeScript 6.0.3, and native TypeScript 7.0.2 all report exactly TS2322 for the invalid kind and TS2353 for the invalid handler key; the valid visitor lookup is accepted and TS2571/TS7053 are absent.
  • Full ts_program and ts_checker suites pass.
  • Stripped ReleaseSafe home-tsc build passed under the 3,840 MB guard at 2,691 MB peak; final frozen-core run peaked at 1,338 MB.
  • Permanent Program regression and untimed docs/README checkpoint are included.

The fix is general: finite string-literal indexed aliases are admitted without publishing object-valued approximations, contextual callback source occurrences survive structural signature interning, and generic defaults use the contextual declaration owner. No corpus edits, skips, casts, source-name branches, or diagnostic suppression.

Sign in to comment on this issue.