fix(mini): export ZodMiniJSONSchema types to prevent TS4023#5511
Merged
colinhacks merged 2 commits intocolinhacks:mainfrom Dec 7, 2025
Merged
fix(mini): export ZodMiniJSONSchema types to prevent TS4023#5511colinhacks merged 2 commits intocolinhacks:mainfrom
colinhacks merged 2 commits intocolinhacks:mainfrom
Conversation
Owner
|
Nice investigation. These non-portable errors can be hard to track down. 👍 |
This was referenced Feb 11, 2026
Open
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.
Bug Fix (Addresses #5200)
The Problem
When using
z.json()fromzod/miniin complex schemas—specifically when the schema is used in a way that requires TypeScript to emit declaration files (for instance, insidepipe,transform, or when used by library authors)—TypeScript fails with error TS4023:Root Cause Analysis
This happens because the return type of
json()(ZodMiniJSONSchema) relies on_ZodMiniJSONSchemaand_ZodMiniJSONSchemaInternals. These types were defined internally inmini/schemas.tsbut were not exported.While this works fine for internal type inference, it breaks when TypeScript tries to generate
.d.tsfiles for consumers, as public interfaces cannot depend on private/unexported types.The Fix
I have added the
exportkeyword to_ZodMiniJSONSchemaand_ZodMiniJSONSchemaInternalsinpackages/zod/src/v4/mini/schemas.ts. This allows TypeScript to correctly reference these types in generated declaration files.Verification & Regression Test
I added a reproduction test case at
packages/zod/src/v4/classic/tests/fix-json-issue.test.ts.Note to Maintainers:
This test file might look slightly unusual because reproducing
TS4023requires specific conditions:Container) to force TypeScript to attempt declaration emission logic.// biome-ignorefornoExportsInTestandnoUnusedImports. This is intentional:_ZodMiniJSONSchemaserves as a compile-time check to ensure the type is now reachable from the outside.src/v4/classic/tests/datetime.test.ts("redos checker").I believe this is a flaky test caused by my local environment's performance limitations and is unrelated to my changes in
mini/schemas.ts. I bypassed the pre-push hook to submit this PR, relying on the CI environment to run the full suite properly.Personal Note
This is my first contribution to Zod (and to open source in general)!
I have done my best to reproduce the issue locally and verify the fix, but I might have missed some project-specific conventions. Please let me know if there are any changes required or if I need to adjust the test implementation. I am more than happy to iterate on this PR until it meets the project's standards.
Thank you for maintaining such an awesome library!