Parent: #548
Problem
Program declaration schemas already preserve conditional types, mapped key identity, and imported overload order, but standard Extract<T, U> is not a transferable utility expression. A source-owned alias that uses Extract therefore makes its imported callable graph unsupported and collapses contextual callback parameters to any.
This is the remaining structural delta behind Zod 4.5.2's VisitHandlers template after #666 and #667.
Fair strict reduction
owner.ts defines a discriminated A | B union and:
export type ItemOfKind<K extends Kind> = [Extract<Item, { kind: K }>] extends [never]
? Item
: Extract<Item, { kind: K }>;
export type Handlers = { [K in Kind]?: (item: ItemOfKind<K>, rewritten: boolean) => Item };
export declare function visit(item: Item, handler: Handler): Item;
export declare function visit(item: Item, handlers: Handlers): Item;The consumer imports visit, passes property a, proves the callback item is A, and keeps independent invalid controls: assignment of A to number, access to A.b, and a missing member on boolean.
TypeScript 6.0.3 and the native TypeScript preview report exactly TS2322 + TS2339 + TS2339. ReleaseFast Home reports two false TS7006 diagnostics and misses all three controls.
Acceptance
- Represent and lower standard
Extract<T, U>through the general Program schema/type machinery with TypeScript's distributive union semantics. - Preserve type-parameter identity through mapped-property specialization and conditional evaluation.
- Keep imported overload ordering and unique object-property selection from #667.
- Add negative controls for nonmatching union members, a
neverextraction/fallback, ambiguity, generics, and optional mapped members. - Add permanent schema and imported Program regressions.
- Match the exact TypeScript 6.0.3/native reduction without weakening diagnostics.
- Run complete Program/checker suites, ReleaseFast, formatting, whitespace, and required Pickier.
- Run the unchanged Zod 4.5.2 identity admission guard twice; require zero additions and document exact removals or an unchanged result.
- Publish detailed evidence and a brief linked README table update.
No Zod path/name/property/line special cases, shallow source-text recognizers, fabricated object shapes, or callback-value-driven overload selection.