fix: avoid deep Deno Zod types#1980
Conversation
Resolves #984
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Reviewed the linked issue (#984), its follow-up reports (Deno 1.x/2.x, JSR, and npm with Zod 4), the complete diff, and the surrounding Zod v3/v4 conversion path.
Validation performed against this head:
./node_modules/.bin/jest tests/helpers/zod.test.ts --runInBand— 23/23 passed, including both v3/v4 runtime conversion coverage and the new output inference test../scripts/build— CJS/ESM builds and declaration generation passed with 0 errors.DENO_DIR=/tmp/deno-pr1980-cache ./scripts/lint— Prettier, ESLint, type checking, Are The Types Wrong, publint, andjsr publish --dry-run(including JSR slow-public-type analysis) all passed.- Deno 2.9.0: the full
client.chat.completions.parse(...)call type-checked against the head with a Zod 4.0.10 consumer mapping. - Additional Deno compile checks confirmed the
_output-based return type preserves transformed output types for bothzod/v3andzod/v4, in both assignability directions.
I also built and checked the base commit using the same local npm-backed setup. That topology did not reproduce the reported TS2589/OOM, so I could not independently recreate the exact deno.land/JSR module-graph failure; however, the JSR slow-type analysis passes on the proposed declaration, and the change removes the full z3.ZodType | z4.ZodType structural comparison that plausibly causes the reported expansion.
Compatibility assessment: existing Zod v3/v4 schemas continue to satisfy the narrower structural contract; runtime schema detection/conversion and parse behavior are unchanged. The signature is technically widened to other objects exposing _output and parse, but that does not break existing callers, and unsupported non-Zod values would still fail in the unchanged conversion path. I found no breaking type/runtime/API change or unhandled Zod v3/v4 regression.
Summary
zodResponseFormat()generic constraint to the small Zod surface the helper actually needs_outputtypeWhy
Issue #984 reports that
deno checkcan fail with TS2589 or exhaust the JavaScript heap when callingzodResponseFormat(). The previous public signature asked Deno to structurally compare the supplied schema against the complete Zod v3 and v4 type graphs before inferring the output type.Impact
Deno no longer needs to expand those full Zod graphs at the call site. The helper still accepts Zod v3 and v4 schemas, produces the same JSON Schema at runtime, and preserves the inferred parsed result through
_output.Validation
pnpm exec jest tests/helpers/zod.test.ts --runInBandpnpm exec tsc --noEmitpnpm run lintResolves #984