zod 4.2.0-canary.20251118T192410 → 4.2.0-canary.20251202T062120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.2.0-canary.20251118T192410",
3
+ "version": "4.2.0-canary.20251202T062120",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -1,4 +1,4 @@
1
- import { test } from "vitest";
1
+ import { expect, test } from "vitest";
2
2
  import * as z from "zod/v3";
3
3
 
4
4
  const crazySchema = z.object({
@@ -40,7 +40,7 @@ const crazySchema = z.object({
40
40
  // });
41
41
 
42
42
  test("parse", () => {
43
- crazySchema.parse({
43
+ const input = {
44
44
  tuple: ["asdf", 1234, true, null, undefined, "1234"],
45
45
  merged: { k1: "asdf", k2: 12 },
46
46
  union: ["asdf", 12, "asdf", 12, "asdf", 12],
@@ -52,5 +52,19 @@ test("parse", () => {
52
52
  nonstrict: { points: 1234 },
53
53
  numProm: Promise.resolve(12),
54
54
  lenfun: (x: string) => x.length,
55
- });
55
+ };
56
+
57
+ const result = crazySchema.parse(input);
58
+
59
+ // Verify the parsed result structure
60
+ expect(result.tuple).toEqual(input.tuple);
61
+ expect(result.merged).toEqual(input.merged);
62
+ expect(result.union).toEqual(input.union);
63
+ expect(result.array).toEqual(input.array);
64
+ expect(result.sumMinLength).toEqual(input.sumMinLength);
65
+ expect(result.intersection).toEqual(input.intersection);
66
+ expect(result.enum).toEqual(input.enum);
67
+ expect(result.nonstrict).toEqual(input.nonstrict);
68
+ expect(result.numProm).toBeInstanceOf(Promise);
69
+ expect(typeof result.lenfun).toBe("function");
56
70
  });
@@ -10,7 +10,8 @@ const func1 = z.function(args1, returns1);
10
10
 
11
11
  test("function parsing", () => {
12
12
  const parsed = func1.parse((arg: any) => arg.length);
13
- parsed("asdf");
13
+ const result = parsed("asdf");
14
+ expect(result).toBe(4);
14
15
  });
15
16
 
16
17
  test("parsed function fail 1", () => {
@@ -226,8 +227,11 @@ test("allow extra parameters", () => {
226
227
  test("params and returnType getters", () => {
227
228
  const func = z.function().args(z.string()).returns(z.string());
228
229
 
229
- func.parameters().items[0].parse("asdf");
230
- func.returnType().parse("asdf");
230
+ const paramResult = func.parameters().items[0].parse("asdf");
231
+ expect(paramResult).toBe("asdf");
232
+
233
+ const returnResult = func.returnType().parse("asdf");
234
+ expect(returnResult).toBe("asdf");
231
235
  });
232
236
 
233
237
  test("inference with transforms", () => {
@@ -6,8 +6,11 @@ import * as z from "zod/v3";
6
6
  const schema = z.nan();
7
7
 
8
8
  test("passing validations", () => {
9
- schema.parse(Number.NaN);
10
- schema.parse(Number("Not a number"));
9
+ const result1 = schema.parse(Number.NaN);
10
+ expect(Number.isNaN(result1)).toBe(true);
11
+
12
+ const result2 = schema.parse(Number("Not a number"));
13
+ expect(Number.isNaN(result2)).toBe(true);
11
14
  });
12
15
 
13
16
  test("failing validations", () => {
@@ -607,25 +607,3 @@ test("safeExtend() on object with refinements should not throw", () => {
607
607
 
608
608
  expect(() => schema.safeExtend({ b: z.string() })).not.toThrow();
609
609
  });
610
-
611
- test("pick() on object with refinements should throw", () => {
612
- const schema = z
613
- .object({
614
- a: z.string(),
615
- b: z.number(),
616
- })
617
- .refine(() => true);
618
-
619
- expect(() => schema.pick({ a: true })).toThrow("Invalid .pick() on object schemas containing refinements");
620
- });
621
-
622
- test("omit() on object with refinements should throw", () => {
623
- const schema = z
624
- .object({
625
- a: z.string(),
626
- b: z.number(),
627
- })
628
- .refine(() => true);
629
-
630
- expect(() => schema.omit({ b: true })).toThrow("Invalid .omit() on object schemas containing refinements");
631
- });
@@ -199,7 +199,7 @@ export function assertNotEqual<A, B>(val: AssertNotEqual<A, B>): AssertNotEqual<
199
199
  export function assertIs<T>(_arg: T): void {}
200
200
 
201
201
  export function assertNever(_x: never): never {
202
- throw new Error();
202
+ throw new Error("Unexpected value in exhaustive check");
203
203
  }
204
204
  export function assert<T>(_: any): asserts _ is T {}
205
205
 
@@ -592,10 +592,8 @@ export const BIGINT_FORMAT_RANGES: Record<checks.$ZodBigIntFormats, [bigint, big
592
592
 
593
593
  export function pick(schema: schemas.$ZodObject, mask: Record<string, unknown>): any {
594
594
  const currDef = schema._zod.def;
595
- if ((currDef.checks ?? []).length > 0) {
596
- throw new Error("Invalid .pick() on object schemas containing refinements");
597
- }
598
- const def = mergeDefs(currDef, {
595
+
596
+ const def = mergeDefs(schema._zod.def, {
599
597
  get shape() {
600
598
  const newShape: Writeable<schemas.$ZodShape> = {};
601
599
  for (const key in mask) {
@@ -617,13 +615,10 @@ export function pick(schema: schemas.$ZodObject, mask: Record<string, unknown>):
617
615
 
618
616
  export function omit(schema: schemas.$ZodObject, mask: object): any {
619
617
  const currDef = schema._zod.def;
620
- if ((currDef.checks ?? []).length > 0) {
621
- throw new Error("Invalid .omit() on object schemas containing refinements");
622
- }
623
618
 
624
- const def = mergeDefs(currDef, {
619
+ const def = mergeDefs(schema._zod.def, {
625
620
  get shape() {
626
- const newShape: Writeable<schemas.$ZodShape> = { ...currDef.shape };
621
+ const newShape: Writeable<schemas.$ZodShape> = { ...schema._zod.def.shape };
627
622
  for (const key in mask) {
628
623
  if (!(key in currDef.shape)) {
629
624
  throw new Error(`Unrecognized key: "${key}"`);
@@ -649,7 +644,7 @@ export function extend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): an
649
644
  const checks = schema._zod.def.checks;
650
645
  const hasChecks = checks && checks.length > 0;
651
646
  if (hasChecks) {
652
- throw new Error("Invalid .extend() on object schemas containing refinements. Use .safeExtend() instead.");
647
+ throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
653
648
  }
654
649
 
655
650
  const def = mergeDefs(schema._zod.def, {
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 12 as number,
4
+ patch: 13 as number,
5
5
  } as const;
package/v4/core/util.cjs CHANGED
@@ -63,7 +63,7 @@ function assertNotEqual(val) {
63
63
  }
64
64
  function assertIs(_arg) { }
65
65
  function assertNever(_x) {
66
- throw new Error();
66
+ throw new Error("Unexpected value in exhaustive check");
67
67
  }
68
68
  function assert(_) { }
69
69
  function getEnumValues(entries) {
@@ -384,10 +384,7 @@ exports.BIGINT_FORMAT_RANGES = {
384
384
  };
385
385
  function pick(schema, mask) {
386
386
  const currDef = schema._zod.def;
387
- if ((currDef.checks ?? []).length > 0) {
388
- throw new Error("Invalid .pick() on object schemas containing refinements");
389
- }
390
- const def = mergeDefs(currDef, {
387
+ const def = mergeDefs(schema._zod.def, {
391
388
  get shape() {
392
389
  const newShape = {};
393
390
  for (const key in mask) {
@@ -407,12 +404,9 @@ function pick(schema, mask) {
407
404
  }
408
405
  function omit(schema, mask) {
409
406
  const currDef = schema._zod.def;
410
- if ((currDef.checks ?? []).length > 0) {
411
- throw new Error("Invalid .omit() on object schemas containing refinements");
412
- }
413
- const def = mergeDefs(currDef, {
407
+ const def = mergeDefs(schema._zod.def, {
414
408
  get shape() {
415
- const newShape = { ...currDef.shape };
409
+ const newShape = { ...schema._zod.def.shape };
416
410
  for (const key in mask) {
417
411
  if (!(key in currDef.shape)) {
418
412
  throw new Error(`Unrecognized key: "${key}"`);
@@ -435,7 +429,7 @@ function extend(schema, shape) {
435
429
  const checks = schema._zod.def.checks;
436
430
  const hasChecks = checks && checks.length > 0;
437
431
  if (hasChecks) {
438
- throw new Error("Invalid .extend() on object schemas containing refinements. Use .safeExtend() instead.");
432
+ throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
439
433
  }
440
434
  const def = mergeDefs(schema._zod.def, {
441
435
  get shape() {
package/v4/core/util.js CHANGED
@@ -7,7 +7,7 @@ export function assertNotEqual(val) {
7
7
  }
8
8
  export function assertIs(_arg) { }
9
9
  export function assertNever(_x) {
10
- throw new Error();
10
+ throw new Error("Unexpected value in exhaustive check");
11
11
  }
12
12
  export function assert(_) { }
13
13
  export function getEnumValues(entries) {
@@ -327,10 +327,7 @@ export const BIGINT_FORMAT_RANGES = {
327
327
  };
328
328
  export function pick(schema, mask) {
329
329
  const currDef = schema._zod.def;
330
- if ((currDef.checks ?? []).length > 0) {
331
- throw new Error("Invalid .pick() on object schemas containing refinements");
332
- }
333
- const def = mergeDefs(currDef, {
330
+ const def = mergeDefs(schema._zod.def, {
334
331
  get shape() {
335
332
  const newShape = {};
336
333
  for (const key in mask) {
@@ -350,12 +347,9 @@ export function pick(schema, mask) {
350
347
  }
351
348
  export function omit(schema, mask) {
352
349
  const currDef = schema._zod.def;
353
- if ((currDef.checks ?? []).length > 0) {
354
- throw new Error("Invalid .omit() on object schemas containing refinements");
355
- }
356
- const def = mergeDefs(currDef, {
350
+ const def = mergeDefs(schema._zod.def, {
357
351
  get shape() {
358
- const newShape = { ...currDef.shape };
352
+ const newShape = { ...schema._zod.def.shape };
359
353
  for (const key in mask) {
360
354
  if (!(key in currDef.shape)) {
361
355
  throw new Error(`Unrecognized key: "${key}"`);
@@ -378,7 +372,7 @@ export function extend(schema, shape) {
378
372
  const checks = schema._zod.def.checks;
379
373
  const hasChecks = checks && checks.length > 0;
380
374
  if (hasChecks) {
381
- throw new Error("Invalid .extend() on object schemas containing refinements. Use .safeExtend() instead.");
375
+ throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
382
376
  }
383
377
  const def = mergeDefs(schema._zod.def, {
384
378
  get shape() {
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 1,
7
- patch: 12,
7
+ patch: 13,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 12,
4
+ patch: 13,
5
5
  };