zod 4.1.4 → 4.1.5

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.1.4",
3
+ "version": "4.1.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -2059,11 +2059,11 @@ export const ZodFunction: core.$constructor<ZodFunction> = /*@__PURE__*/ core.$c
2059
2059
  );
2060
2060
 
2061
2061
  export function _function(): ZodFunction;
2062
- export function _function<const In extends Array<core.$ZodType> = Array<core.$ZodType>>(params: {
2062
+ export function _function<const In extends ReadonlyArray<core.$ZodType>>(params: {
2063
2063
  input: In;
2064
2064
  }): ZodFunction<ZodTuple<In, null>, core.$ZodFunctionOut>;
2065
2065
  export function _function<
2066
- const In extends Array<core.$ZodType> = Array<core.$ZodType>,
2066
+ const In extends ReadonlyArray<core.$ZodType>,
2067
2067
  const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut,
2068
2068
  >(params: {
2069
2069
  input: In;
@@ -130,6 +130,46 @@ test("valid function run", () => {
130
130
  });
131
131
  });
132
132
 
133
+ const args3 = [
134
+ z.object({
135
+ f1: z.number(),
136
+ f2: z.string().nullable(),
137
+ f3: z.array(z.boolean().optional()).optional(),
138
+ }),
139
+ ] as const;
140
+ const returns3 = z.union([z.string(), z.number()]);
141
+
142
+ const func3 = z.function({
143
+ input: args3,
144
+ output: returns3,
145
+ });
146
+
147
+ test("function inference 3", () => {
148
+ type func3 = (typeof func3)["_input"];
149
+
150
+ expectTypeOf<func3>().toEqualTypeOf<
151
+ (arg: {
152
+ f3?: (boolean | undefined)[] | undefined;
153
+ f1: number;
154
+ f2: string | null;
155
+ }) => string | number
156
+ >();
157
+ });
158
+
159
+ test("valid function run", () => {
160
+ const validFunc3Instance = func3.implement((_x) => {
161
+ _x.f2;
162
+ _x.f3![0];
163
+ return "adf" as any;
164
+ });
165
+
166
+ validFunc3Instance({
167
+ f1: 21,
168
+ f2: "asdf",
169
+ f3: [true, false],
170
+ });
171
+ });
172
+
133
173
  test("input validation error", () => {
134
174
  const schema = z.function({
135
175
  input: z.tuple([z.string()]),
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 4 as number,
4
+ patch: 5 as number,
5
5
  } as const;
@@ -624,10 +624,10 @@ export interface ZodFunction<Args extends core.$ZodFunctionIn = core.$ZodFunctio
624
624
  }
625
625
  export declare const ZodFunction: core.$constructor<ZodFunction>;
626
626
  export declare function _function(): ZodFunction;
627
- export declare function _function<const In extends Array<core.$ZodType> = Array<core.$ZodType>>(params: {
627
+ export declare function _function<const In extends ReadonlyArray<core.$ZodType>>(params: {
628
628
  input: In;
629
629
  }): ZodFunction<ZodTuple<In, null>, core.$ZodFunctionOut>;
630
- export declare function _function<const In extends Array<core.$ZodType> = Array<core.$ZodType>, const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
630
+ export declare function _function<const In extends ReadonlyArray<core.$ZodType>, const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
631
631
  input: In;
632
632
  output: Out;
633
633
  }): ZodFunction<ZodTuple<In, null>, Out>;
@@ -624,10 +624,10 @@ export interface ZodFunction<Args extends core.$ZodFunctionIn = core.$ZodFunctio
624
624
  }
625
625
  export declare const ZodFunction: core.$constructor<ZodFunction>;
626
626
  export declare function _function(): ZodFunction;
627
- export declare function _function<const In extends Array<core.$ZodType> = Array<core.$ZodType>>(params: {
627
+ export declare function _function<const In extends ReadonlyArray<core.$ZodType>>(params: {
628
628
  input: In;
629
629
  }): ZodFunction<ZodTuple<In, null>, core.$ZodFunctionOut>;
630
- export declare function _function<const In extends Array<core.$ZodType> = Array<core.$ZodType>, const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
630
+ export declare function _function<const In extends ReadonlyArray<core.$ZodType>, const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
631
631
  input: In;
632
632
  output: Out;
633
633
  }): ZodFunction<ZodTuple<In, null>, Out>;
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 1,
7
- patch: 4,
7
+ patch: 5,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 4,
4
+ patch: 5,
5
5
  };