ReviewOS

home-lang/home

fix(ts): avoid undefined from optional access on narrowed receivers

#776
Closed glennmichael123 opened this 8 days ago ·
8 days ago

Parent: #548 · Tracker: #416

The unchanged Zod 4.5.2 core gate reports a false diagnostic at core/schemas.ts:339:3. In the failure branch of a discriminated SafeParseResult, result.error is required and non-null. TypeScript therefore types result.error?.issues as the required issues array; Home re-adds undefined solely because optional-access syntax was written, making the returned failure object incompatible with StandardSchemaV1.FailureResult.

A strict standalone reduction with Success | Failure, a discriminated SafeResult, an unannotated toResult helper, and synchronous/promise validate branches is clean in TypeScript 6.0.3 and native TypeScript 7.0.2. Current ReleaseFast Home emits TS2322 because it infers issues as readonly Issue[] | undefined.

Acceptance:

  • optional property and element access add undefined only when the receiver can still be nullish after flow narrowing;
  • keep ordinary nullable-receiver optional chains and their short-circuit semantics unchanged;
  • exact three-engine positive/negative oracle parity;
  • remove only the schemas.ts:339 identity from the unchanged Zod core gate, with zero additions;
  • full checker suite and optimized guarded build pass;
  • no Zod/source-name/path/diagnostic special case.
8 days ago

Implemented in d1d9abb and documented in 54ad7e8 + 07c6dc4.

Evidence:

  • optional access adds undefined only when the flow-narrowed receiver can still be nullish; the permanent positive/negative checker oracle passes;
  • the unchanged Zod 4.5.2 core set drops only core/schemas.ts:339:3 TS2741 from this issue, with no added identity;
  • combined #775/#776 gate is 8 -> 6 identities; final normalized SHA-256 is 64abd7817175b2885f805e3580a8ed0b74727e15f456dde3d85ba9ee3c528d19;
  • full checker and Program suites pass;
  • stripped ReleaseSafe home-tsc passed under the unchanged 3,840 MB guard at 2,603 MB peak.

No Zod/source/path/diagnostic special case, corpus edit, suppression, or raised memory ceiling.

Sign in to comment on this issue.