Parent
Problem
Home does not preserve the non-Promise constituent after a terminating instanceof Promise guard. This leaves local T | Promise<T> values as the full union and degrades imported projected members to any, which removes contextual types from downstream array callbacks.
The concrete Zod 4.5.2 consequence is four TS7006 diagnostics in src/v4/core/parse.ts at the result.issues.map((iss) => ...) callbacks in sync/async parse and safe-parse paths.
Fair oracle
Two modules, with the producer exporting the ordinary structural types below:
export type MaybeAsync<T> = T | Promise<T>;
export interface Payload { value: unknown; issues: string[]; }
export interface SchemaInternals {
run(payload: Payload): MaybeAsync<Payload>;
}
export interface Schema { _zod: SchemaInternals; }Consumer:
import type { Schema } from "./schema.js";
export function parse(schema: Schema): unknown {
const result = schema._zod.run({ value: undefined, issues: [] });
if (result instanceof Promise) throw new Error("async");
result.issues.map((issue) => issue.toUpperCase());
return result.value;
}Controls establish that a directly returned imported Payload already provides string callback context, while the same MaybeAsync shape declared locally also fails to narrow.
Compiler options: strict, noEmit, skipLibCheck, target: ES2022, module/moduleResolution: NodeNext.
Current and expected
- TypeScript 6.0.3: clean
- tsgo native preview 7.0.0-
dad1862: clean - Home ReleaseSafe: imported oracle reports TS7006; local control additionally retains TS2339 on
issuesandvalue
Expected: clean, with the false/continuation branch narrowed to Payload and issue contextually typed as string.
Acceptance
- Implement structural
instanceof Promiseunion subtraction without source-name or project-specific special cases. - Cover local and imported/module-resolved
T | Promise<T>returns. - Preserve contextual array callback element types after narrowing.
- Add focused regression tests.
- Re-run the exact Zod diagnostic baseline and introduce zero new diagnostic identities.
- Publish detailed benchmark/correctness evidence and update the README summary table.