fix(v4): emit falsy prefault values in toJSONSchema (#5824)#5893
Conversation
Fixes colinhacks#5824 The function used a truthiness check () which filtered out falsy prefault values like , , and . Changed to use so all prefault values are correctly emitted as JSON Schema defaults.
|
Reviewed PR #5893 — approved with no issues. The fix correctly replaces a truthiness check ( Task list (4/4 completed)
|
|
TL;DR — Fixes Key changes
Summary | 2 files | 1 commit | base:
The root cause is a single-character class of bug: using a value as a boolean guard when the value's domain includes falsy members. The fix is minimal — one conditional changed from truthiness to
|
There was a problem hiding this comment.
Reviewed — no issues found.
Task list (4/4 completed)
- Read the PR diff and understand the changes
- Read the modified source file for full context
- Verify correctness of the fix and test coverage
- Submit review
Claude Opus | 𝕏
|
Landed in Zod 4.4 |

What
Fixes #5824
The
toJsonSchemafunction used a truthiness check (result.schema._prefault) when deciding whether to emit a prefault value as a JSON Schema default. This silently dropped falsy prefault values likefalse,0, and"".How
Changed the check from:
to:
This ensures all prefault values — including falsy ones — are correctly emitted as JSON Schema defaults.
Reproduction
Tests
Added a test case for falsy prefaults (
false,0,""). All 3713 existing tests pass.