ReviewOS

home-lang/home

fix(ts): resolve default-lib collection interfaces in type annotations

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

Problem

Home reports false TS2304 diagnostics for default-lib generic collection interfaces in ordinary type annotations:

const weak: WeakMap<object, boolean> = new WeakMap();
declare const readonlyMap: ReadonlyMap<string, number>;
declare const readonlySet: ReadonlySet<string>;

TypeScript 6.0.3 and the TypeScript 7 native preview accept these declarations. This also accounts for four unique TS2304 diagnostics in the pinned Zod corpus (WeakMap twice, ReadonlyMap, and ReadonlySet).

Root cause

The generic type-reference resolver has semantic builders for Map, Set, and WeakSet, but no WeakMap arm and no read-only collection builders. Its generic-name acceptance registry also omits WeakMap, WeakSet, ReadonlyMap, and ReadonlySet.

Fair oracle

Positive:

  • WeakMap<object, boolean> resolves and exposes its standard methods.
  • ReadonlyMap<string, number> exposes read methods.
  • ReadonlySet<string> exposes read methods.
  • TypeScript 6.0.3 and TypeScript 7: 0 diagnostics.
  • Home parent: 3 false TS2304 diagnostics.

Negative controls:

  • MissingCollection<string> must remain TS2304.
  • ReadonlyMap#set and ReadonlySet#add must remain TS2339.

Acceptance criteria

  • Resolve the default-lib collection interfaces through shared semantic collection construction, not name suppression.
  • Preserve key/value and method result types.
  • Do not expose mutable-only members on read-only interfaces.
  • Preserve the negative controls in parity with TypeScript 6 and 7.
  • Add permanent regression coverage.
  • Re-run the pinned Zod corpus and document the result in the TypeScript performance audit and README.

Tracks #416 and #548.

8 days ago

Implementation is live on main in 3e4f37c (fix(ts): resolve default-lib collection interfaces (#662)).

Fair validation:

  • focused checker regression: pass
  • positive standalone oracle: TypeScript 6.0.3, native TypeScript preview, and optimized Home all report zero diagnostics
  • negative oracle: all three engines report the same four diagnostic keys: TS2304 for an unknown MissingCollection, TS2339 for ReadonlyMap.set, TS2339 for ReadonlySet.add, and TS2322 for assigning WeakMap.get's boolean | undefined result to boolean
  • pinned Zod 4.5.2 combined differential from the #661 baseline: 436 diagnostics / 431 unique locations -> 430 / 425; six removals, zero additions

The removed set contains the four collection-name TS2304s targeted here plus one #664 TS2345 and one #663 TS2698. Full-suite and documentation evidence will follow before closure.

8 days ago

Completed on main in 3e4f37c; the combined published audit is in f26b768 and README. TypeScript 6.0.3, the native TypeScript preview, and ReleaseFast Home all accept the positive collection project and report the same TS2304/TS2339/TS2339/TS2322 negative controls. The unchanged Zod 4.5.2 audit finishes at 430 diagnostics / 425 unique identities with zero candidate-only identities. Full checker and Program suites plus a clean-cache ReleaseFast build pass. Closing as completed.

Sign in to comment on this issue.