ReviewOS

home-lang/home

fix(ts): propagate outer constraints through conditional indexed aliases

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

Follow-up under #548 and #416 after #658.

The two remaining pinned Zod TS2344 diagnostics are both Record<core.output<Key>, ...>. core.output<T> is T extends { _zod: { output: any } } ? T["_zod"]["output"] : unknown, while Key is constrained to a schema whose output is string | number | symbol. TypeScript propagates that outer constraint through the conditional indexed-access alias; Home leaves the result as unknown and rejects the otherwise valid Record key.

A strict same-file reduction defines the same conditional alias. For Key extends Schema<string | number | symbol>, TypeScript 6.0.3 and native TypeScript 7.0.2 accept Record<OutputOf<Key>, unknown>, while current ReleaseFast Home reports TS2344. An appended unconstrained Record<OutputOf<T>, unknown> remains invalid and all three report exactly one TS2344 there. Home currently reports two.

Resolve a generic conditional/indexed alias through the outer type parameter's declared constraint when that constraint proves the conditional branch and property-key result. Preserve symbolic behavior when the outer parameter is unconstrained or the branch cannot be proven. Do not special-case Record, _zod, output, Zod names, or suppress TS2344.

Add permanent positive/appended-negative controls calibrated against TS 6.0.3 and native TS 7.0.2, run complete checker and Program suites, and compare every pinned Zod diagnostic identity against the 448/443 #658 checkpoint and immutable 602/597 baseline. Keep timing gated on zero under #548.

Provenance: #658 implementation 0ffa175; docs f880159.

8 days ago

Implemented and validated the general dependent-base-constraint fix.

What changed:

  • base-constraint analysis now re-evaluates deferred conditional TypeIds over the declared constraint of their check parameter;
  • generic alias syntax is instantiated with each argument’s effective base constraint, so conditional indexed-access bodies reduce through the ordinary evaluator;
  • qualified source-local type aliases resolve by declaration identity through namespace/import-equals paths;
  • no Record, _zod, output, or Zod-specific branch was added.

Fair oracle (/tmp/home-ts-conditional-key):

  • unqualified constrained Record<OutputOf<Key>, unknown>: clean in Home ReleaseFast, TS 6.0.3, and native TS 7.0.2;
  • qualified constrained Record<core.output<Key>, unknown>: clean;
  • unconstrained Record<OutputOf<T>, unknown> / Record<core.output<T>, unknown>: each retains exactly one TS2344.

Pinned Zod 4.5.2 audit:

  • parent #658: 448 diagnostics / 443 unique keys;
  • candidate #659: 446 diagnostics / 441 unique keys;
  • exactly the two targeted src/v4/core/schemas.ts:3089:20 and :3090:12 TS2344 keys removed;
  • 0 keys added versus #658;
  • 156 unique keys removed and 0 added versus the immutable #548 baseline.

Validation:

  • focused regression: pass;
  • all constraint-filtered checker tests: pass;
  • full checker: 4,355/4,355;
  • Program transfer: 189/189;
  • ReleaseFast build: pass (wall time excluded due shared-machine contention);
  • zig fmt --check, scoped Pickier, and git diff --check: pass.
8 days ago

Closed by 1332e4e6f on main. The implementation evidence and zero-regression Zod audit are recorded above; documentation follows in a separate commit linked to #416.

8 days ago

Documentation is published on main in 5d72ab3fd: the README now includes the compact Zod table and TS_PERFORMANCE contains the complete oracle, corpus, and validation record.

Sign in to comment on this issue.