ReviewOS

home-lang/home

fix(ts): preserve union-of-arrays precedence in JSDoc imports

#974
Open glennmichael123 opened this 1 day ago ·
1 day ago

Related #846, #973, #960, #66.

An admitted checked-JavaScript owner exports /** @type {ReadonlyArray<number[] | string[]>} */ const readonlyNested = [[1], ["one"]. TypeScript 5.7.3 gives an importer readonlyNested[0] the type number[] | string[]; Home gives it (number[] | string)[]. The same mismatch occurs for mutable Array<number[] | string[]>. This also changes the result of flat() in the #973 oracle.

Root cause: packages/ts_program/src/jsdoc_types.zig strips [] from any type text ending in that suffix before splitting a top-level union. After removing the outer ReadonlyArray<...>, it treats number[] | string[] as (number[] | string)[]. A suffix after a top-level union belongs only to the final constituent. Parenthesized (number[] | string[])[] has different semantics and must remain an array of a union.

Acceptance: parse both forms with distinct container placement; preserve the correct schema across checked-JavaScript imports with checkJs on and off; match TypeScript 5.7.3 exact CLI diagnostics for source element and flat() result; run focused parser/Program/checker, full Program/checker/LSP, and expanded exact-stream audit under the agreed memory guard. No parenthesized fixture workaround.

1 day ago

The parser fix and a focused unit assertion for ReadonlyArray<number[] | string[]> versus (number[] | string[])[] are in the working checkout. A guarded home-tsc built before the latest checker edit now gives the imported element the correct semantic type in both checkJs modes. TypeScript 5.7.3 controls report four intended TS2322 errors in the combined #973 fixture. Exact prose still differs for a separate union display-order reason, tracked as #975; the nested-chain difference has a focused checker patch awaiting a guarded rebuild. Host memory remains below the agreed 40% Zig build admission gate, so this issue is not yet verified or closed.

1 day ago

Pushed af1df1444 to origin/main as Glenn, without coauthors. It fixes the postfix-array versus top-level-union precedence in the JSDoc parser, adds a focused parser assertion, and adds checked-JavaScript import oracles for both checkJs modes. TypeScript 5.7.3 and Home produce the exact same single TS2322 stream and exit 2 for both new configs; the full Program suite passed under the 3,840 MB guard.

The separate combined flat() fixture still differs in #975's union display order, and #973 retains the explicit-depth and indexed-object semantics gaps. #974 stays open until its full combined exact-stream acceptance is met.

Sign in to comment on this issue.