Related #846 and #960. Reproducer in the admitted checked-JS readonly-array fixture: import readonlyValues from owner.js; add an otherwise unused type Alias<U> = U; before a call such as readonlyValues.flatMap(() => readonlyValues). TypeScript 5.7.3 still reports only the intentional result-assignment TS2322. Home additionally reports TS2345 on the flatMap callback, and can also reject earlier flatMap calls in the file. An unrelated declare function collect<U>(value: U): U; also triggers the extra TS2345, while renaming that formal parameter to V removes it. This is a declaration-scope/type-parameter identity leak, not a legitimate array constraint. Merely changing the synthetic array prototype U to a fresh TypeId did not fix the observed behavior. Fix the underlying scope or inference ownership and add a negative cross-declaration regression; do not special-case the name or suppress TS2345. This remains open after the independent flatMap union-inference and callback-signature fix.
fix(ts): isolate generic U declarations from array method inference
#962Resolved on origin/main by 641dcfc and c622d23. Corrected root cause: firstFreeTypeParameter read the aggregate is_type_parameter flag before traversing a union. For the flatMap callback return U | U[], it could therefore return the union TypeId as the method binder. That TypeId indexes the union payload, not the type-parameter payload; adding an unrelated generic U changed which payload index was in range and exposed the false TS2345. The fix traverses union/intersection members before accepting a direct parameter. The checker regression asserts the registered flatMap binder is the actual synthetic U and distinct from the alias U. A TypeScript 5.7.3 CLI oracle checks imported checked-JS readonly and mutable arrays plus a local readonly array in both checkJs modes, with exactly one intentional TS2322 and no TS2345. Verification: full direct checker binary 4706/4706 passed under the 3840 MB guard; zig build test-tsc-streams -j1 passed under the same guard; Zig formatting and diff checks passed. This closes only this cross-declaration flatMap bug, not all of #846 or #960.
Sign in to comment on this issue.