zod 3.25.18 → 3.25.21

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.
@@ -594,15 +594,16 @@ const z = __importStar(require("zod/v4"));
594
594
  (0, vitest_1.expect)(() => z.parse(e, 123)).toThrow();
595
595
  });
596
596
  // this returns both a schema and a check
597
- (0, vitest_1.test)("z.custom", () => {
597
+ (0, vitest_1.test)("z.custom schema", () => {
598
598
  const a = z.custom((val) => {
599
599
  return typeof val === "string";
600
600
  });
601
601
  (0, vitest_1.expect)(z.parse(a, "hello")).toEqual("hello");
602
602
  (0, vitest_1.expect)(() => z.parse(a, 123)).toThrow();
603
- const b = z.string().check(z.custom((val) => val.length > 3));
604
- (0, vitest_1.expect)(z.parse(b, "hello")).toEqual("hello");
605
- (0, vitest_1.expect)(() => z.parse(b, "hi")).toThrow();
603
+ });
604
+ (0, vitest_1.test)("z.custom check", () => {
605
+ // @ts-expect-error Inference not possible, use z.refine()
606
+ z.date().check(z.custom((val) => val.getTime() > 0));
606
607
  });
607
608
  (0, vitest_1.test)("z.check", () => {
608
609
  // this is a more flexible version of z.custom that accepts an arbitrary _parse logic
@@ -631,7 +631,7 @@ export interface ZodCustom<O = unknown, I = unknown> extends ZodType {
631
631
  }
632
632
  export declare const ZodCustom: core.$constructor<ZodCustom>;
633
633
  export declare function check<O = unknown>(fn: core.CheckFn<O>, params?: string | core.$ZodCustomParams): core.$ZodCheck<O>;
634
- export declare function custom<O = unknown, I = O>(fn?: (data: O) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, I>;
634
+ export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
635
635
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
636
636
  export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>, params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
637
637
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
@@ -67,7 +67,7 @@ export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
67
67
  readonly input: Input;
68
68
  }
69
69
  export interface $ZodIssueCustom extends $ZodIssueBase {
70
- readonly code?: "custom";
70
+ readonly code: "custom";
71
71
  readonly params?: Record<string, any> | undefined;
72
72
  readonly input: unknown;
73
73
  }
@@ -96,6 +96,7 @@ export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
96
96
  }
97
97
  export type $ZodStringFormatIssues = $ZodIssueStringCommonFormats | $ZodIssueStringInvalidRegex | $ZodIssueStringInvalidJWT | $ZodIssueStringStartsWith | $ZodIssueStringEndsWith | $ZodIssueStringIncludes;
98
98
  export type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom;
99
+ export type $ZodIssueCode = $ZodIssue["code"];
99
100
  export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
100
101
  type RawIssue<T extends $ZodIssueBase> = util.Flatten<util.MakePartial<T, "message" | "path"> & {
101
102
  /** The input data */
@@ -723,7 +723,9 @@ export interface $ZodLiteral<T extends util.Primitive = util.Primitive> extends
723
723
  _zod: $ZodLiteralInternals<T>;
724
724
  }
725
725
  export declare const $ZodLiteral: core.$constructor<$ZodLiteral>;
726
- interface File {
726
+ declare global {
727
+ interface File {
728
+ }
727
729
  }
728
730
  export interface $ZodFileDef extends $ZodTypeDef {
729
731
  type: "file";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.25.18",
3
+ "version": "3.25.21",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",
@@ -1962,10 +1962,10 @@ export function check<O = unknown>(fn: core.CheckFn<O>, params?: string | core.$
1962
1962
  return ch;
1963
1963
  }
1964
1964
 
1965
- export function custom<O = unknown, I = O>(
1966
- fn?: (data: O) => unknown,
1965
+ export function custom<O>(
1966
+ fn?: (data: unknown) => unknown,
1967
1967
  _params?: string | core.$ZodCustomParams | undefined
1968
- ): ZodCustom<O, I> {
1968
+ ): ZodCustom<O, O> {
1969
1969
  return core._custom(ZodCustom, fn ?? (() => true), _params) as any;
1970
1970
  }
1971
1971
 
@@ -1,6 +1,8 @@
1
1
  import { expect, expectTypeOf, test } from "vitest";
2
2
  import * as z from "zod/v4";
3
3
 
4
+ declare const iss: z.core.$ZodIssueCode;
5
+
4
6
  const Test = z.object({
5
7
  f1: z.number(),
6
8
  f2: z.string().optional(),
@@ -706,17 +706,17 @@ test("z.templateLiteral", () => {
706
706
  });
707
707
 
708
708
  // this returns both a schema and a check
709
- test("z.custom", () => {
709
+ test("z.custom schema", () => {
710
710
  const a = z.custom((val) => {
711
711
  return typeof val === "string";
712
712
  });
713
713
  expect(z.parse(a, "hello")).toEqual("hello");
714
714
  expect(() => z.parse(a, 123)).toThrow();
715
+ });
715
716
 
716
- const b = z.string().check(z.custom((val) => val.length > 3));
717
-
718
- expect(z.parse(b, "hello")).toEqual("hello");
719
- expect(() => z.parse(b, "hi")).toThrow();
717
+ test("z.custom check", () => {
718
+ // @ts-expect-error Inference not possible, use z.refine()
719
+ z.date().check(z.custom((val) => val.getTime() > 0));
720
720
  });
721
721
 
722
722
  test("z.check", () => {
@@ -86,7 +86,7 @@ export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
86
86
  }
87
87
 
88
88
  export interface $ZodIssueCustom extends $ZodIssueBase {
89
- readonly code?: "custom";
89
+ readonly code: "custom";
90
90
  readonly params?: Record<string, any> | undefined;
91
91
  readonly input: unknown;
92
92
  }
@@ -149,6 +149,8 @@ export type $ZodIssue =
149
149
  | $ZodIssueInvalidValue
150
150
  | $ZodIssueCustom;
151
151
 
152
+ export type $ZodIssueCode = $ZodIssue["code"];
153
+
152
154
  export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
153
155
  type RawIssue<T extends $ZodIssueBase> = util.Flatten<
154
156
  util.MakePartial<T, "message" | "path"> & {
@@ -2865,7 +2865,10 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
2865
2865
  //////////////////////////////////////////
2866
2866
 
2867
2867
  // provide a fallback in case the File interface isn't provided in the environment
2868
- interface File {}
2868
+ declare global {
2869
+ interface File {}
2870
+ }
2871
+
2869
2872
  export interface $ZodFileDef extends $ZodTypeDef {
2870
2873
  type: "file";
2871
2874
  }