ReviewOS

home-lang/home

fix(ts): combine generic callback signatures on array unions

#972
Closed glennmichael123 opened this 18 hours ago ·
18 hours ago

Related: #960, #963, #846, #66.

TypeScript 5.7.3 accepts values.map(value => value) inside function read<T extends number[]>(values: T | readonly string[]). Its callback parameter has type string | number, its third callback parameter has type readonly string[] | number[], and its result is (string | number)[]. The matched control reports only deliberate TS2322 assignments of the union element to string and number.

Home originally rejected the union as non-iterable and reported TS2339 for map, because aggregate unions inherit is_type_parameter and an early unconstrained-parameter branch intercepted union traversal. The #963 follow-up in progress corrects that traversal and makes map visible. Home then reports TS2322 at the callback return (string versus number) and loses the intended result assignment diagnostic. This is a separate generic union-signature combination gap, not an array-member visibility gap.

Code: packages/ts_checker/src/check.zig resolves the union's two map<U> signatures through lookupArrayLikePrototypeMember; collectResolvedUnionSignatures returns false when either signature has free generic parameters, and later call resolution checks the callback against one branch. TypeScript combines the generic signatures and contextually types the callback over both array constituents.

Acceptance: implement the union generic-call semantics without a map-specific diagnostic suppression. Preserve the callback's union element and receiver types, infer the mutable result array, and retain readonly mutator exclusions. Add exact TypeScript 5.7.3 CLI oracle fixtures, checker regressions, and guarded full checker/Program/LSP verification.

1 hour ago

Implemented and pushed as 1eb43a5ab on origin/main (Glenn, no coauthors). Generic signatures of callable unions now align equivalent type-parameter binders before combining, intersection callback signatures supply union parameter context, the contextual recheck preserves that combined context, and the generic call infers its result from the checked callback. Nested readonly-to-mutable diagnostics use the existing relation's TypeScript explanation.

The matched TypeScript 5.7.3 fixture now reports exactly the three intentional TS2322 diagnostics, including string | number callback values, the number[] | readonly string[] receiver, and (string | number)[] result. Focused and full checker, Program, and LSP suites passed under the 3,840 MB guard. Fresh home-tsc and the admitted-JavaScript exact-stream audit passed 151/151 configs. Related work: #960, #963, #846, #66.

Sign in to comment on this issue.