zod 4.1.0-canary.20250806T002637 → 4.1.0-canary.20250821T014902

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.0-canary.20250806T002637",
3
+ "version": "4.1.0-canary.20250821T014902",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -118,6 +118,7 @@ export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$Z
118
118
  export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
119
119
  core.$ZodType.init(inst, def);
120
120
  inst.def = def;
121
+ inst.type = def.type;
121
122
  Object.defineProperty(inst, "_def", { value: def });
122
123
 
123
124
  // base methods
@@ -1688,7 +1689,7 @@ export function _default<T extends core.SomeType>(
1688
1689
  type: "default",
1689
1690
  innerType: innerType as any as core.$ZodType,
1690
1691
  get defaultValue() {
1691
- return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
1692
+ return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
1692
1693
  },
1693
1694
  }) as any;
1694
1695
  }
@@ -1716,7 +1717,7 @@ export function prefault<T extends core.SomeType>(
1716
1717
  type: "prefault",
1717
1718
  innerType: innerType as any as core.$ZodType,
1718
1719
  get defaultValue() {
1719
- return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
1720
+ return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
1720
1721
  },
1721
1722
  }) as any;
1722
1723
  }
@@ -311,3 +311,15 @@ test("partial should not clobber defaults", () => {
311
311
  }
312
312
  `);
313
313
  });
314
+
315
+ test("defaulted object schema returns shallow clone", () => {
316
+ const schema = z
317
+ .object({
318
+ a: z.string(),
319
+ })
320
+ .default({ a: "x" });
321
+ const result1 = schema.parse(undefined);
322
+ const result2 = schema.parse(undefined);
323
+ expect(result1).not.toBe(result2);
324
+ expect(result1).toEqual(result2);
325
+ });
@@ -38,8 +38,9 @@ test("failing validations", () => {
38
38
  "origin": "file",
39
39
  "code": "too_small",
40
40
  "minimum": 5,
41
+ "inclusive": true,
41
42
  "path": [],
42
- "message": "Too small: expected file to have >5 bytes"
43
+ "message": "Too small: expected file to have >=5 bytes"
43
44
  }
44
45
  ]],
45
46
  "success": false,
@@ -52,8 +53,9 @@ test("failing validations", () => {
52
53
  "origin": "file",
53
54
  "code": "too_big",
54
55
  "maximum": 8,
56
+ "inclusive": true,
55
57
  "path": [],
56
- "message": "Too big: expected file to have <8 bytes"
58
+ "message": "Too big: expected file to have <=8 bytes"
57
59
  }
58
60
  ]],
59
61
  "success": false,
@@ -827,3 +827,18 @@ test("def typing", () => {
827
827
  z.string().catch("fallback").def.type satisfies "catch";
828
828
  z.file().def.type satisfies "file";
829
829
  });
830
+
831
+ test("runtime type property exists and returns correct values", () => {
832
+ const stringSchema = z.string();
833
+ expect(stringSchema.type).toBe("string");
834
+ });
835
+
836
+ test("type narrowing works with type property", () => {
837
+ type ArrayOrRecord = z.ZodArray<z.ZodString> | z.ZodRecord<z.ZodString, z.ZodAny>;
838
+ const arraySchema = z.array(z.string()) as ArrayOrRecord;
839
+
840
+ if (arraySchema.type === "array") {
841
+ expectTypeOf(arraySchema).toEqualTypeOf<z.ZodArray<z.ZodString>>();
842
+ expect(arraySchema.element).toBeDefined();
843
+ }
844
+ });
@@ -35,3 +35,15 @@ test("prefault inside object", () => {
35
35
  email: string;
36
36
  }>();
37
37
  });
38
+
39
+ test("object schema with prefault should return shallow clone", () => {
40
+ const schema = z
41
+ .object({
42
+ a: z.string(),
43
+ })
44
+ .default({ a: "x" });
45
+ const result1 = schema.parse(undefined);
46
+ const result2 = schema.parse(undefined);
47
+ expect(result1).not.toBe(result2);
48
+ expect(result1).toEqual(result2);
49
+ });
@@ -155,7 +155,8 @@ test("min/max", async () => {
155
155
  [
156
156
  {
157
157
  "code": "too_small",
158
- "message": "Too small: expected set to have >4 items",
158
+ "inclusive": true,
159
+ "message": "Too small: expected set to have >=4 items",
159
160
  "minimum": 4,
160
161
  "origin": "set",
161
162
  "path": [],
@@ -169,8 +170,9 @@ test("min/max", async () => {
169
170
  [
170
171
  {
171
172
  "code": "too_big",
173
+ "inclusive": true,
172
174
  "maximum": 5,
173
- "message": "Too big: expected set to have <5 items",
175
+ "message": "Too big: expected set to have <=5 items",
174
176
  "origin": "set",
175
177
  "path": [],
176
178
  },
@@ -1321,7 +1321,7 @@ export function _default<T extends schemas.$ZodObject>(
1321
1321
  type: "default",
1322
1322
  innerType,
1323
1323
  get defaultValue() {
1324
- return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
1324
+ return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
1325
1325
  },
1326
1326
  }) as any;
1327
1327
  }
@@ -470,6 +470,7 @@ export const $ZodCheckMaxSize: core.$constructor<$ZodCheckMaxSize> = /*@__PURE__
470
470
  origin: util.getSizableOrigin(input),
471
471
  code: "too_big",
472
472
  maximum: def.maximum,
473
+ inclusive: true,
473
474
  input,
474
475
  inst,
475
476
  continue: !def.abort,
@@ -519,6 +520,7 @@ export const $ZodCheckMinSize: core.$constructor<$ZodCheckMinSize> = /*@__PURE__
519
520
  origin: util.getSizableOrigin(input),
520
521
  code: "too_small",
521
522
  minimum: def.minimum,
523
+ inclusive: true,
522
524
  input,
523
525
  inst,
524
526
  continue: !def.abort,
@@ -168,9 +168,7 @@ export interface $ZodType<
168
168
  "~standard": $ZodStandardSchema<this>;
169
169
  }
170
170
  export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
171
- extends $ZodType<T["output"], T["input"], T> {
172
- // _zod: T;
173
- }
171
+ extends $ZodType<T["output"], T["input"], T> {}
174
172
 
175
173
  export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
176
174
  inst ??= {} as any;
@@ -1721,7 +1719,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1721
1719
  const _normalized = util.cached(() => {
1722
1720
  const keys = Object.keys(def.shape);
1723
1721
  for (const k of keys) {
1724
- if (!(def.shape[k] instanceof $ZodType)) {
1722
+ if (!def.shape[k]._zod.traits.has("$ZodType")) {
1725
1723
  throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1726
1724
  }
1727
1725
  }
@@ -3642,7 +3640,8 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
3642
3640
  $ZodType.init(inst, def);
3643
3641
  const regexParts: string[] = [];
3644
3642
  for (const part of def.parts) {
3645
- if (part instanceof $ZodType) {
3643
+ if (typeof part === "object" && part !== null) {
3644
+ // is Zod schema
3646
3645
  if (!part._zod.pattern) {
3647
3646
  // if (!source)
3648
3647
  throw new Error(`Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}`);
@@ -389,6 +389,11 @@ export function isPlainObject(o: any): o is Record<PropertyKey, unknown> {
389
389
  return true;
390
390
  }
391
391
 
392
+ export function shallowClone(o: any): any {
393
+ if (isPlainObject(o)) return { ...o };
394
+ return o;
395
+ }
396
+
392
397
  export function numKeys(data: any): number {
393
398
  let keyCount = 0;
394
399
  for (const key in data) {
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 0,
4
- patch: 15 as number,
4
+ patch: 17 as number,
5
5
  } as const;
@@ -9,6 +9,7 @@ export interface ZodMiniType<
9
9
  out Input = unknown,
10
10
  out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
11
11
  > extends core.$ZodType<Output, Input, Internals> {
12
+ type: Internals["def"]["type"];
12
13
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
13
14
  clone(def?: Internals["def"], params?: { parent: boolean }): this;
14
15
  register<R extends core.$ZodRegistry>(
@@ -43,7 +44,9 @@ export const ZodMiniType: core.$constructor<ZodMiniType> = /*@__PURE__*/ core.$c
43
44
  if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
44
45
 
45
46
  core.$ZodType.init(inst, def);
47
+
46
48
  inst.def = def;
49
+ inst.type = def.type;
47
50
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
48
51
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
49
52
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
@@ -1256,7 +1259,7 @@ export function _default<T extends SomeType>(
1256
1259
  type: "default",
1257
1260
  innerType: innerType as any as core.$ZodType,
1258
1261
  get defaultValue() {
1259
- return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
1262
+ return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
1260
1263
  },
1261
1264
  }) as any;
1262
1265
  }
@@ -1281,7 +1284,7 @@ export function prefault<T extends SomeType>(
1281
1284
  type: "prefault",
1282
1285
  innerType: innerType as any as core.$ZodType,
1283
1286
  get defaultValue() {
1284
- return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
1287
+ return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
1285
1288
  },
1286
1289
  }) as any;
1287
1290
  }
@@ -869,3 +869,31 @@ test("def typing", () => {
869
869
  z.catch(z.string(), "fallback").def.type satisfies "catch";
870
870
  z.file().def.type satisfies "file";
871
871
  });
872
+
873
+ test("defaulted object schema returns shallow clone", () => {
874
+ const schema = z._default(
875
+ z.object({
876
+ a: z.string(),
877
+ }),
878
+ { a: "x" }
879
+ );
880
+ const result1 = schema.parse(undefined);
881
+ const result2 = schema.parse(undefined);
882
+ expect(result1).not.toBe(result2);
883
+ expect(result1).toEqual(result2);
884
+ });
885
+
886
+ test("runtime type property exists and returns correct values", () => {
887
+ const stringSchema = z.string();
888
+ expect(stringSchema.type).toBe("string");
889
+ });
890
+
891
+ test("type narrowing works with type property", () => {
892
+ type ArrayOrRecord = z.ZodMiniArray<z.ZodMiniString> | z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>;
893
+ const arraySchema = z.array(z.string()) as ArrayOrRecord;
894
+
895
+ if (arraySchema.type === "array") {
896
+ expectTypeOf(arraySchema).toEqualTypeOf<z.ZodMiniArray<z.ZodMiniString<unknown>>>();
897
+ expect(arraySchema.def.element).toBeDefined();
898
+ }
899
+ });
@@ -115,6 +115,7 @@ const parse = __importStar(require("./parse.cjs"));
115
115
  exports.ZodType = core.$constructor("ZodType", (inst, def) => {
116
116
  core.$ZodType.init(inst, def);
117
117
  inst.def = def;
118
+ inst.type = def.type;
118
119
  Object.defineProperty(inst, "_def", { value: def });
119
120
  // base methods
120
121
  inst.check = (...checks) => {
@@ -920,7 +921,7 @@ function _default(innerType, defaultValue) {
920
921
  type: "default",
921
922
  innerType: innerType,
922
923
  get defaultValue() {
923
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
924
+ return typeof defaultValue === "function" ? defaultValue() : index_js_1.util.shallowClone(defaultValue);
924
925
  },
925
926
  });
926
927
  }
@@ -934,7 +935,7 @@ function prefault(innerType, defaultValue) {
934
935
  type: "prefault",
935
936
  innerType: innerType,
936
937
  get defaultValue() {
937
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
938
+ return typeof defaultValue === "function" ? defaultValue() : index_js_1.util.shallowClone(defaultValue);
938
939
  },
939
940
  });
940
941
  }
@@ -6,6 +6,7 @@ import * as parse from "./parse.js";
6
6
  export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
7
7
  core.$ZodType.init(inst, def);
8
8
  inst.def = def;
9
+ inst.type = def.type;
9
10
  Object.defineProperty(inst, "_def", { value: def });
10
11
  // base methods
11
12
  inst.check = (...checks) => {
@@ -815,7 +816,7 @@ export function _default(innerType, defaultValue) {
815
816
  type: "default",
816
817
  innerType: innerType,
817
818
  get defaultValue() {
818
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
819
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
819
820
  },
820
821
  });
821
822
  }
@@ -829,7 +830,7 @@ export function prefault(innerType, defaultValue) {
829
830
  type: "prefault",
830
831
  innerType: innerType,
831
832
  get defaultValue() {
832
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
833
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
833
834
  },
834
835
  });
835
836
  }
package/v4/core/api.cjs CHANGED
@@ -882,7 +882,7 @@ function _default(Class, innerType, defaultValue) {
882
882
  type: "default",
883
883
  innerType,
884
884
  get defaultValue() {
885
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
885
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
886
886
  },
887
887
  });
888
888
  }
package/v4/core/api.js CHANGED
@@ -747,7 +747,7 @@ export function _default(Class, innerType, defaultValue) {
747
747
  type: "default",
748
748
  innerType,
749
749
  get defaultValue() {
750
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
750
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
751
751
  },
752
752
  });
753
753
  }
@@ -269,6 +269,7 @@ exports.$ZodCheckMaxSize = core.$constructor("$ZodCheckMaxSize", (inst, def) =>
269
269
  origin: util.getSizableOrigin(input),
270
270
  code: "too_big",
271
271
  maximum: def.maximum,
272
+ inclusive: true,
272
273
  input,
273
274
  inst,
274
275
  continue: !def.abort,
@@ -296,6 +297,7 @@ exports.$ZodCheckMinSize = core.$constructor("$ZodCheckMinSize", (inst, def) =>
296
297
  origin: util.getSizableOrigin(input),
297
298
  code: "too_small",
298
299
  minimum: def.minimum,
300
+ inclusive: true,
299
301
  input,
300
302
  inst,
301
303
  continue: !def.abort,
package/v4/core/checks.js CHANGED
@@ -243,6 +243,7 @@ export const $ZodCheckMaxSize = /*@__PURE__*/ core.$constructor("$ZodCheckMaxSiz
243
243
  origin: util.getSizableOrigin(input),
244
244
  code: "too_big",
245
245
  maximum: def.maximum,
246
+ inclusive: true,
246
247
  input,
247
248
  inst,
248
249
  continue: !def.abort,
@@ -270,6 +271,7 @@ export const $ZodCheckMinSize = /*@__PURE__*/ core.$constructor("$ZodCheckMinSiz
270
271
  origin: util.getSizableOrigin(input),
271
272
  code: "too_small",
272
273
  minimum: def.minimum,
274
+ inclusive: true,
273
275
  input,
274
276
  inst,
275
277
  continue: !def.abort,
@@ -710,7 +710,7 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
710
710
  const _normalized = util.cached(() => {
711
711
  const keys = Object.keys(def.shape);
712
712
  for (const k of keys) {
713
- if (!(def.shape[k] instanceof exports.$ZodType)) {
713
+ if (!def.shape[k]._zod.traits.has("$ZodType")) {
714
714
  throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
715
715
  }
716
716
  }
@@ -1632,7 +1632,8 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
1632
1632
  exports.$ZodType.init(inst, def);
1633
1633
  const regexParts = [];
1634
1634
  for (const part of def.parts) {
1635
- if (part instanceof exports.$ZodType) {
1635
+ if (typeof part === "object" && part !== null) {
1636
+ // is Zod schema
1636
1637
  if (!part._zod.pattern) {
1637
1638
  // if (!source)
1638
1639
  throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
@@ -679,7 +679,7 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
679
679
  const _normalized = util.cached(() => {
680
680
  const keys = Object.keys(def.shape);
681
681
  for (const k of keys) {
682
- if (!(def.shape[k] instanceof $ZodType)) {
682
+ if (!def.shape[k]._zod.traits.has("$ZodType")) {
683
683
  throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
684
684
  }
685
685
  }
@@ -1601,7 +1601,8 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
1601
1601
  $ZodType.init(inst, def);
1602
1602
  const regexParts = [];
1603
1603
  for (const part of def.parts) {
1604
- if (part instanceof $ZodType) {
1604
+ if (typeof part === "object" && part !== null) {
1605
+ // is Zod schema
1605
1606
  if (!part._zod.pattern) {
1606
1607
  // if (!source)
1607
1608
  throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
package/v4/core/util.cjs CHANGED
@@ -24,6 +24,7 @@ exports.randomString = randomString;
24
24
  exports.esc = esc;
25
25
  exports.isObject = isObject;
26
26
  exports.isPlainObject = isPlainObject;
27
+ exports.shallowClone = shallowClone;
27
28
  exports.numKeys = numKeys;
28
29
  exports.escapeRegex = escapeRegex;
29
30
  exports.clone = clone;
@@ -217,6 +218,11 @@ function isPlainObject(o) {
217
218
  }
218
219
  return true;
219
220
  }
221
+ function shallowClone(o) {
222
+ if (isPlainObject(o))
223
+ return { ...o };
224
+ return o;
225
+ }
220
226
  function numKeys(data) {
221
227
  let keyCount = 0;
222
228
  for (const key in data) {
@@ -136,6 +136,7 @@ export declare const allowsEval: {
136
136
  value: boolean;
137
137
  };
138
138
  export declare function isPlainObject(o: any): o is Record<PropertyKey, unknown>;
139
+ export declare function shallowClone(o: any): any;
139
140
  export declare function numKeys(data: any): number;
140
141
  export declare const getParsedType: (data: any) => ParsedTypes;
141
142
  export declare const propertyKeyTypes: Set<string>;
package/v4/core/util.d.ts CHANGED
@@ -136,6 +136,7 @@ export declare const allowsEval: {
136
136
  value: boolean;
137
137
  };
138
138
  export declare function isPlainObject(o: any): o is Record<PropertyKey, unknown>;
139
+ export declare function shallowClone(o: any): any;
139
140
  export declare function numKeys(data: any): number;
140
141
  export declare const getParsedType: (data: any) => ParsedTypes;
141
142
  export declare const propertyKeyTypes: Set<string>;
package/v4/core/util.js CHANGED
@@ -170,6 +170,11 @@ export function isPlainObject(o) {
170
170
  }
171
171
  return true;
172
172
  }
173
+ export function shallowClone(o) {
174
+ if (isPlainObject(o))
175
+ return { ...o };
176
+ return o;
177
+ }
173
178
  export function numKeys(data) {
174
179
  let keyCount = 0;
175
180
  for (const key in data) {
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 0,
7
- patch: 15,
7
+ patch: 17,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 0,
4
- patch: 15,
4
+ patch: 17,
5
5
  };
@@ -121,6 +121,7 @@ exports.ZodMiniType = core.$constructor("ZodMiniType", (inst, def) => {
121
121
  throw new Error("Uninitialized schema in ZodMiniType.");
122
122
  core.$ZodType.init(inst, def);
123
123
  inst.def = def;
124
+ inst.type = def.type;
124
125
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
125
126
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
126
127
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
@@ -686,7 +687,7 @@ function _default(innerType, defaultValue) {
686
687
  type: "default",
687
688
  innerType: innerType,
688
689
  get defaultValue() {
689
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
690
+ return typeof defaultValue === "function" ? defaultValue() : index_js_1.util.shallowClone(defaultValue);
690
691
  },
691
692
  });
692
693
  }
@@ -699,7 +700,7 @@ function prefault(innerType, defaultValue) {
699
700
  type: "prefault",
700
701
  innerType: innerType,
701
702
  get defaultValue() {
702
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
703
+ return typeof defaultValue === "function" ? defaultValue() : index_js_1.util.shallowClone(defaultValue);
703
704
  },
704
705
  });
705
706
  }
@@ -2,6 +2,7 @@ import * as core from "../core/index.cjs";
2
2
  import { util } from "../core/index.cjs";
3
3
  type SomeType = core.SomeType;
4
4
  export interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
5
+ type: Internals["def"]["type"];
5
6
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
6
7
  clone(def?: Internals["def"], params?: {
7
8
  parent: boolean;
@@ -2,6 +2,7 @@ import * as core from "../core/index.js";
2
2
  import { util } from "../core/index.js";
3
3
  type SomeType = core.SomeType;
4
4
  export interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
5
+ type: Internals["def"]["type"];
5
6
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
6
7
  clone(def?: Internals["def"], params?: {
7
8
  parent: boolean;
@@ -6,6 +6,7 @@ export const ZodMiniType = /*@__PURE__*/ core.$constructor("ZodMiniType", (inst,
6
6
  throw new Error("Uninitialized schema in ZodMiniType.");
7
7
  core.$ZodType.init(inst, def);
8
8
  inst.def = def;
9
+ inst.type = def.type;
9
10
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
10
11
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
11
12
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
@@ -575,7 +576,7 @@ export function _default(innerType, defaultValue) {
575
576
  type: "default",
576
577
  innerType: innerType,
577
578
  get defaultValue() {
578
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
579
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
579
580
  },
580
581
  });
581
582
  }
@@ -588,7 +589,7 @@ export function prefault(innerType, defaultValue) {
588
589
  type: "prefault",
589
590
  innerType: innerType,
590
591
  get defaultValue() {
591
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
592
+ return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
592
593
  },
593
594
  });
594
595
  }