Tighten preprocess return types#5908
Conversation
|
Reviewed PR #5908 — approved. The type-level machinery correctly constrains preprocess return types while preserving backward compatibility for Task list (3/3 completed)
|
|
TL;DR — Adds a compile-time compatibility check to Key changes
Summary | 2 files | 1 commit | base: Structural return-type constraint for
|
There was a problem hiding this comment.
Reviewed — no issues found.
Task list (3/3 completed)
- Checkout PR and read the diff
- Read changed files and trace data flow
- Self-critique and submit review
Claude Opus | 𝕏

Adds a type-level compatibility check for
z.preprocess()callback returns so clear mismatches are caught before the value reaches the target schema, while preserving the existing<A, U, B>generic shape and validation-boundary patterns likeunknown,unknown[], object wrappers,void, andz.NEVER.Covers the regression reported in #5733 with focused type assertions for sync, async, union, array, object, and default-schema cases.
Validated with
pnpm exec tsc -p packages/zod/tsconfig.test.json --noEmit --extendedDiagnosticsandpnpm vitest run packages/zod/src/v4/classic/tests/preprocess.test.ts.