ReviewOS

home-lang/home

fix(ts): instantiate recursive generic interface indexes at concrete type arguments

#952
Closed glennmichael123 opened this 7 days ago ·
7 days ago

Related: #846, #950, #951. TypeScript 5.7.3 and current Home differ on a forward/recursive generic interface with inherited index signatures. Minimal strict/noEmit source:

interface Alpha<T> { make(): Beta<T> }
interface MixedBase<T> { readonly [key: string]: T | (() => Beta<T>); [index: number]: T }
interface Beta<T> extends Alpha<T>, MixedBase<T> {}
declare const alpha: Alpha<number>;
const beta = alpha.make();
beta["new"] = 2;
beta[0] = 2;
beta["0"] = 2;

TypeScript 5.7.3 reports only TS2542 at line 6, naming Beta<number>. Home reports TS2542 naming Beta<T> and an additional TS2322 at line 7 because it checks the mutable number index against unresolved T. The string-index write must fail and the number/numeric-string writes must remain legal. The generic-interface refresh and forward instantiation paths in packages/ts_checker/src/check.zig are candidates to inspect, but root cause has not yet been established. Fix the concrete substitution rather than suppressing TS2322; add checker/Program/CLI regressions and verify under the 3,840 MB guard. Keep #951 focused on readonly-domain provenance, with this issue tracking the separate concrete-generic instantiation failure.

7 days ago

The red, standalone reproducer is now on main in 23c23c7 at packages/ts_cli/testdata/issue952-forward-generic-index/. Rechecked with TypeScript 5.7.3 and a freshly built Home CLI: TypeScript gives one TS2542 at line 6 naming Beta<number>; Home gives TS2542 naming Beta<T> plus an invalid TS2322 at line 7. It is intentionally not in the passing stream suite until the concrete substitution is fixed.

7 days ago

Resolved by be95309 and d58b8f0 on main. The provisional callable return was refreshed in the formal generic scope; it now refreshes in the concrete receiver scope. The red fixture now matches TypeScript 5.7.3 exactly: one TS2542 naming Beta<number>, no false TS2322. Checker, Program, CLI stream, and tsc_main guarded suites exited 0; positive and negative controls are included.

Sign in to comment on this issue.