ReviewOS

home-lang/home

fix(ts): preserve unique symbol identity in array keyof

#970
Closed glennmichael123 opened this 8 hours ago ·
8 hours ago

Related: #960, #846, #66.

TypeScript 5.7.3 control (--lib es2023 --strict --noEmit):

declare const readonlyValues: readonly number[];
const key: keyof readonly number[] = Symbol.unscopables; // accepted
declare const other: unique symbol;
const wrong: keyof readonly number[] = other; // TS2322, unique symbol

Home currently emits TS2322 for both assignments and renders the second source as broad symbol. The well-known Symbol.unscopables property in symbolGlobalType is Primitive.symbol_t; keyofTypeFromOperand turns synthetic Symbol.unscopables member names into string literal keys. An ordinary symbol, another unique symbol, and the well-known key must remain distinct. Replacing all three with broad symbol would incorrectly accept wrong.

Acceptance: represent well-known and declared unique symbols with stable type identity; resolve their computed property keys into the same identity in keyof, indexed access, assignment and type display; accept the first assignment and reject the second with the TypeScript 5.7.3 diagnostic. Add matched TypeScript/Home CLI oracles for readonly and mutable arrays, focused checker coverage, and guarded checker/Program/LSP runs. Do not special-case this one spelling in the assignment diagnostic.

4 hours ago

Implemented and pushed to origin/main:

  • 080a6c8d6: nominal well-known and declared unique symbol types; computed member keys preserve identity through keyof, indexed access, mapped utility types, substitution, Program schema transfer, and LSP display. Direct global Symbol()/Symbol.for() initializers retain the declaration's fresh identity while unrelated symbols remain rejected.
  • f29126d47: mutable/readonly array and computed-interface TypeScript controls.
  • 654c354cb: imported-key/Readonly<Box> control and exact-stream audit registration.

Verification against TypeScript 5.7.3: 148/148 exact CLI streams, including all three new configs; guarded checker 4,742/4,742, Program 473/473, LSP 144/144. Pickier and staged whitespace checks passed. The test binary and builds ran sequentially under the 3,840 MB memory guard. This completes this issue's stated acceptance; broader #960/#846/#963 and Bun parity #66 remain tracked separately.

Sign in to comment on this issue.