zod 4.2.0-canary.20250827T203557 → 4.2.0-canary.20250911T000242

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.20250827T203557",
3
+ "version": "4.2.0-canary.20250911T000242",
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()]),
@@ -1862,6 +1862,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1862
1862
 
1863
1863
  const proms: Promise<any>[] = [];
1864
1864
  const shape = value.shape;
1865
+
1865
1866
  for (const key of value.keys) {
1866
1867
  const el = shape[key]!;
1867
1868
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
@@ -1907,7 +1908,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
1907
1908
  }
1908
1909
 
1909
1910
  // A: preserve key order {
1910
- doc.write(`const newResult = {}`);
1911
+ doc.write(`const newResult = {};`);
1911
1912
  for (const key of normalized.keys) {
1912
1913
  const id = ids[key];
1913
1914
  const k = util.esc(key);
@@ -1920,6 +1921,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
1920
1921
  })));
1921
1922
  }
1922
1923
 
1924
+
1923
1925
  if (${id}.value === undefined) {
1924
1926
  if (${k} in input) {
1925
1927
  newResult[${k}] = undefined;
@@ -1927,6 +1929,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
1927
1929
  } else {
1928
1930
  newResult[${k}] = ${id}.value;
1929
1931
  }
1932
+
1930
1933
  `);
1931
1934
  }
1932
1935
 
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 3 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>;
@@ -864,7 +864,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
864
864
  ids[key] = `key_${counter++}`;
865
865
  }
866
866
  // A: preserve key order {
867
- doc.write(`const newResult = {}`);
867
+ doc.write(`const newResult = {};`);
868
868
  for (const key of normalized.keys) {
869
869
  const id = ids[key];
870
870
  const k = util.esc(key);
@@ -877,6 +877,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
877
877
  })));
878
878
  }
879
879
 
880
+
880
881
  if (${id}.value === undefined) {
881
882
  if (${k} in input) {
882
883
  newResult[${k}] = undefined;
@@ -884,6 +885,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
884
885
  } else {
885
886
  newResult[${k}] = ${id}.value;
886
887
  }
888
+
887
889
  `);
888
890
  }
889
891
  doc.write(`payload.value = newResult;`);
@@ -833,7 +833,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
833
833
  ids[key] = `key_${counter++}`;
834
834
  }
835
835
  // A: preserve key order {
836
- doc.write(`const newResult = {}`);
836
+ doc.write(`const newResult = {};`);
837
837
  for (const key of normalized.keys) {
838
838
  const id = ids[key];
839
839
  const k = util.esc(key);
@@ -846,6 +846,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
846
846
  })));
847
847
  }
848
848
 
849
+
849
850
  if (${id}.value === undefined) {
850
851
  if (${k} in input) {
851
852
  newResult[${k}] = undefined;
@@ -853,6 +854,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
853
854
  } else {
854
855
  newResult[${k}] = ${id}.value;
855
856
  }
857
+
856
858
  `);
857
859
  }
858
860
  doc.write(`payload.value = newResult;`);
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 1,
7
- patch: 3,
7
+ patch: 5,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 3,
4
+ patch: 5,
5
5
  };