Skip to content

Commit c5f349b

Browse files
committed
Fix z.undefined() behavior in toJSONSchema
1 parent 5267f90 commit c5f349b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/zod/src/v4/core/to-json-schema.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,17 @@ export class JSONSchemaGenerator {
227227
case "unknown": {
228228
break;
229229
}
230-
case "undefined": {
231-
const json = _json as JSONSchema.NullSchema;
232-
json.type = "null";
230+
case "undefined":
231+
case "void": {
232+
if (this.unrepresentable === "throw") {
233+
throw new Error("Undefined cannot be represented in JSON Schema");
234+
}
233235
break;
234236
}
235237
case "never": {
236238
_json.not = {};
237239
break;
238240
}
239-
case "void": {
240-
if (this.unrepresentable === "throw") {
241-
throw new Error("Void cannot be represented in JSON Schema");
242-
}
243-
break;
244-
}
245241
case "date": {
246242
if (this.unrepresentable === "throw") {
247243
throw new Error("Date cannot be represented in JSON Schema");

0 commit comments

Comments
 (0)