ReviewOS

home-lang/home

fix(ts): contextually type returned imported callables

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

Parents: #548, #416

The admitted Zod 4.5.2 baseline on a5ae69070 contains 60 identical TS7006 diagnostics across src/v4/locales/*.ts. Every locale declares an annotated factory such as:

import type * as errors from "../core/errors.js";
const error: () => errors.$ZodErrorMap = () => {
  return (issue) => issue.code;
};

$ZodErrorMap is an imported callable interface whose parameter is $ZodRawIssue<T>. TypeScript 6.0.3 and native TypeScript 7.0.2 contextually type issue; Home loses the callable return context and reports TS7006.

Implement the general contextual-typing fix at the source-owned Program schema / checker boundary. Preserve the callable interface's parameter and result graph when it appears as the return type of an annotated function and contextually types a returned arrow. Do not special-case Zod, infer from source text, or suppress noImplicitAny.

Required controls:

  • imported callable interface used as an annotated factory return;
  • qualified namespace import and direct type import forms;
  • deliberate wrong callback return/body access proving the transferred type is enforced;
  • local/shadowed names must not borrow foreign schema facts;
  • repeated prepared-owner queries must not reparse or check the owner;
  • exact same-parent Zod A/B with two deterministic ReleaseFast runs and zero additions before any timing claim.
8 days ago

Implementation checkpoint on exact parent 3ff2b325a:

  • faithful $ZodRawIssue<T> reduction now has no TS7006 for qualified or direct imported callable factories;
  • local shadow control remains clean;
  • deliberate unknown-property and numeric-return callbacks produce exactly two TS2322 diagnostics, matching the reference codes;
  • source-owned schema now retains canonical PropertyKey, Record, and homomorphic utility nodes instead of copying checker-local IDs or degrading them to any;
  • mapped substitution now resolves nested generic members and preserves effective index signatures through mapped intersections.

Added source-graph and end-to-end Program regressions; zig build test -Dfilter=ts_program passes. Next: exact same-parent ReleaseFast Zod A/B and full focused checker/CLI verification.

8 days ago

Landed on main in three small commits:

  • b300135 — fix(ts): retain contextual callable read contracts (#617)
  • c70c495 — test(ts): cover returned imported callables (#617)
  • 77deef9 — docs(ts): record returned callable admission (#617)

Final focused controls:

  • qualified namespace and direct type-import factories both retain callable return context;
  • unknown property access emits TS2339 and numeric return emits TS2322, exactly matching TS 6.0.3 and native TS 7.0.2 codes;
  • local ErrorMap shadow remains local;
  • 32 repeated prepared-owner queries leave node, type, and diagnostic counts unchanged, with no owner check;
  • dedicated Program suite passes 172/172;
  • focused final ReleaseFast output is exactly TS2339 + TS2322, with no TS7006.

Exact same-parent Zod 4.5.2 ReleaseFast A/B on parent 5ac3860, two complete alternating runs per binary:

  • parent: 1,148 diagnostics, including 443 TS7006;
  • candidate: 1,088 diagnostics, including 383 TS7006;
  • normalized set difference: 60 removals, all TS7006; 0 additions; every other code/count unchanged;
  • within-arm diagnostic outputs are byte-identical after removing only the time trailer;
  • wall seconds: parent 27.32 / 26.62, candidate 26.53 / 26.01. This two-run sample is documented but not admitted as a speed claim.

The README and TS performance documentation now link and report the result. Zod remains untimed and unadmitted under #548 because 1,088 diagnostics remain.

Sign in to comment on this issue.