fix: complete zod/v4 migration (supersedes #158)#161
Merged
Conversation
Test files were importing z from 'zod' while src/ now imports from 'zod/v4'. TypeScript treats those as nominally distinct types, and the mismatch causes type instantiation to explode through tRPC's generic machinery, OOMing tsc. Also cast the named-object examples in the multipleExamples test to preserve existing runtime behavior — zod-openapi v5 types meta examples as unknown[], but the runtime still accepts the v3-style record form. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR completes the Zod v4 “permalink import” migration by switching internal and test-suite Zod imports to zod/v4 and widening the package’s zod peer dependency to support both zod@^3.25 and zod@^4.
Changes:
- Widen
zodpeer dependency to^3.25.0 || ^4.0.0. - Migrate
src/andtest/Zod imports fromzodtozod/v4to prevent nominal type mismatches (and the resultingtscOOM). - Adjust one test’s
.meta({ examples })typing to compile under the updated zod-openapi typings.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Widens zod peer dependency range to support ^3.25 and ^4. |
| src/utils/zod.ts | Switches Zod imports to zod/v4 for consistent typing/runtime. |
| src/utils/procedure.ts | Switches Zod imports to zod/v4 for consistent typing/runtime. |
| src/types.ts | Updates ZodObject type import to come from zod/v4. |
| src/generator/schema.ts | Switches Zod imports to zod/v4 for consistent schema generation typing. |
| src/generator/index.ts | Switches ZodSchema import to zod/v4 for defs typing. |
| src/adapters/node-http/core.ts | Switches Zod imports to zod/v4 to keep runtime checks/types consistent. |
| test/generator.test.ts | Updates import to zod/v4 and adds a type assertion for .meta({ examples }). |
| test/adapters/standalone.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
| test/adapters/nuxt.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
| test/adapters/next.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
| test/adapters/koa.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
| test/adapters/fetch.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
| test/adapters/fastify.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
| test/adapters/express.test.ts | Updates Zod import to zod/v4 to avoid nominal mismatches in tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addresses Copilot review on #161: - ZodSchema, ZodObject, ZodAny, ZodRawShape, ZodType, ZodError are only used in type positions — move them to `import type` so stricter TypeScript settings (verbatimModuleSyntax, preserveValueImports) don't emit unused value imports. - ZodTypeAny was imported in node-http/core.ts but never referenced — remove it. - Replace the broad `as never` cast on the multipleExamples test with `as unknown as unknown[]` plus a comment explaining why the runtime still accepts the v3-style named-record form. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
|
Addressed all 6 Copilot review comments in 4ab0e19:
`pnpm run build` (tsc + jest + cjs + esm) green: 129/129 tests passing, full build succeeds. |
mcampa
added a commit
that referenced
this pull request
May 22, 2026
- feat: contact/license fields on GenerateOpenApiDocumentOptions (#157) - feat: support zod v3 (>=3.25) alongside v4 via zod/v4 permalink (#161) - fix: bump zod-openapi to 5.4.6 and raise peer dep to ^5.4.4 to prevent the discriminated-union crash on zod >=4.1.13 (#162) - fix: add x-${string} index signature to contact/license types (#160) - chore: bump h3 to ^1.15.5 (#159) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #158 by rebasing onto current master and fixing the CI failure.
Summary
#158 widens the zod peer dependency to `^3.25.0 || ^4.0.0` and switches `src/` imports from `'zod'` to `'zod/v4'`, per the zod docs for package authors. That PR fails CI with a `tsc` OOM, because all `test/` files still `import { z } from 'zod'`. TypeScript treats `ZodObject` from `'zod'` and `'zod/v4'` as nominally distinct types — even though they resolve to the same runtime class in `zod@4.0.14` — and the mismatch explodes type instantiation through tRPC's generic `Procedure`/`Router` machinery via `OpenApiMeta`, exhausting Node's heap.
See investigation: #158 (comment).
Changes
Test plan
🤖 Generated with Claude Code