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 +1 -1
- package/src/v4/classic/schemas.ts +2 -2
- package/src/v4/classic/tests/function.test.ts +40 -0
- package/src/v4/core/versions.ts +1 -1
- package/v4/classic/schemas.d.cts +2 -2
- package/v4/classic/schemas.d.ts +2 -2
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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()]),
|
package/src/v4/core/versions.ts
CHANGED
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -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
|
|
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
|
|
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>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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>;
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED