zod 4.0.0-beta.20250430T185432 → 4.0.0-beta.20250504T215252

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/src/schemas.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as core from "@zod/core";
2
2
  import { util } from "@zod/core";
3
+
3
4
  import * as checks from "./checks.js";
4
5
  import * as iso from "./iso.js";
5
6
  import * as parse from "./parse.js";
@@ -23,12 +24,12 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
23
24
  def: this["_zod"]["def"];
24
25
  /** @deprecated Use `.def` instead. */
25
26
  _def: this["_zod"]["def"];
26
- /** @deprecated Use `z.output<typeof schema>` instead. */
27
- _output: this["_zod"]["output"];
28
- /** @deprecated Use `z.input<typeof schema>` instead. */
29
- _input: this["_zod"]["input"];
27
+ // /** @deprecated Use `z.output<typeof schema>` instead. */
28
+ _output: core.output<this>;
29
+ // /** @deprecated Use `z.input<typeof schema>` instead. */
30
+ _input: core.input<this>;
30
31
  // base methods
31
- check(...checks: (core.CheckFn<this["_zod"]["output"]> | core.$ZodCheck<this["_zod"]["output"]>)[]): this;
32
+ check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
32
33
  clone(def?: this["_zod"]["def"]): this;
33
34
  register<R extends core.$ZodRegistry>(
34
35
  registry: R,
@@ -38,9 +39,10 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
38
39
  : [core.$ZodRegistry<R["_meta"], this>["_meta"]]
39
40
  : ["Incompatible schema"]
40
41
  ): this;
42
+
41
43
  brand<T extends PropertyKey = PropertyKey>(
42
44
  value?: T
43
- ): this & Record<"_zod", Record<"output", this["_zod"]["output"] & core.$brand<T>>>;
45
+ ): PropertyKey extends T ? this : this & Record<"_zod", Record<"~output", core.output<this> & core.$brand<T>>>;
44
46
 
45
47
  // parsing
46
48
  parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
@@ -665,7 +667,7 @@ export interface _ZodNumber<Input = unknown> extends ZodType {
665
667
  max(value: number, params?: string | core.$ZodCheckLessThanParams): this;
666
668
  /** Consider `z.int()` instead. This API is considered *legacy*; it will never be removed but a better alternative exists. */
667
669
  int(params?: string | core.$ZodCheckNumberFormatParams): this;
668
- /** @deprecated This is now identical to `.int()` instead. Only numbers in the safe integer range are accepted. */
670
+ /** @deprecated This is now identical to `.int()`. Only numbers in the safe integer range are accepted. */
669
671
  safe(params?: string | core.$ZodCheckNumberFormatParams): this;
670
672
  positive(params?: string | core.$ZodCheckGreaterThanParams): this;
671
673
  nonnegative(params?: string | core.$ZodCheckGreaterThanParams): this;
@@ -1006,297 +1008,83 @@ export function array<T extends core.$ZodType>(element: core.$ZodType, params?:
1006
1008
  return core._array(ZodArray, element, params) as any;
1007
1009
  }
1008
1010
 
1009
- // ZodObjectLike
1010
- export interface ZodObjectLike<out O = object, out I = object> extends ZodType {
1011
- _zod: core.$ZodObjectLikeInternals<O, I>;
1012
- }
1013
- export const ZodObjectLike: core.$constructor<ZodObjectLike> = /*@__PURE__*/ core.$constructor(
1014
- "ZodObjectLike",
1015
- (inst, def) => {
1016
- core.$ZodObjectLike.init(inst, def);
1017
- ZodType.init(inst, def);
1018
- }
1019
- );
1020
-
1021
1011
  // .keyof
1022
- export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["def"]["shape"]>;
1023
- export function keyof<T extends ZodInterface>(schema: T): ZodLiteral<keyof T["_zod"]["output"]>;
1024
- export function keyof(schema: ZodObjectLike) {
1025
- const shape =
1026
- schema._zod.def.type === "interface"
1027
- ? util.cleanInterfaceShape(schema._zod.def.shape).shape
1028
- : schema._zod.def.shape;
1029
-
1012
+ export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["output"]> {
1013
+ const shape = schema._zod.def.shape;
1030
1014
  return literal(Object.keys(shape)) as any;
1031
1015
  }
1032
1016
 
1033
- // ZodInterface
1034
- type ZodInterfacePartial<
1035
- T extends ZodInterface,
1036
- Keys extends keyof T["_zod"]["def"]["shape"] = keyof T["_zod"]["def"]["shape"],
1037
- > = ZodInterface<
1038
- util.Extend<
1039
- T["_zod"]["def"]["shape"],
1040
- {
1041
- [k in Keys]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1042
- }
1043
- >,
1044
- {
1045
- optional: T["_zod"]["optional"] | (string & Keys);
1046
- defaulted: T["_zod"]["defaulted"];
1047
- extra: T["_zod"]["extra"];
1048
- }
1049
- >;
1050
-
1051
- type ZodInterfaceRequired<
1052
- T extends ZodInterface,
1053
- Keys extends keyof T["_zod"]["def"]["shape"] = keyof T["_zod"]["def"]["shape"],
1054
- > = ZodInterface<
1055
- util.Extend<
1056
- T["_zod"]["def"]["shape"],
1057
- {
1058
- [k in Keys]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1059
- }
1060
- >,
1061
- {
1062
- optional: never;
1063
- defaulted: T["_zod"]["defaulted"];
1064
- extra: T["_zod"]["extra"];
1065
- }
1066
- >;
1067
-
1068
- export type MergeInterfaces<A extends ZodInterface, B extends ZodInterface> = ZodInterface<
1069
- util.Extend<A["_zod"]["def"]["shape"], B["_zod"]["def"]["shape"]>,
1070
- util.MergeInterfaceParams<A, B>
1071
- >;
1072
-
1073
- export interface ZodInterface<
1074
- // @ts-ignore cast variance
1075
- out Shape extends core.$ZodLooseShape = core.$ZodLooseShape,
1076
- // @ts-ignore cast variance
1077
- out Params extends core.$ZodInterfaceNamedParams = core.$ZodInterfaceNamedParams,
1078
- > extends ZodType {
1079
- _zod: core.$ZodInterfaceInternals<Shape, Params>;
1080
-
1081
- keyof(): ZodEnum<util.ToEnum<util.InterfaceKeys<string & keyof Shape>>>;
1082
- catchall<T extends core.$ZodType>(
1083
- schema: T
1084
- ): ZodInterface<
1085
- Shape,
1086
- {
1087
- optional: Params["optional"];
1088
- defaulted: Params["defaulted"];
1089
- extra: Record<string, T["_zod"]["output"]>;
1090
- }
1091
- >;
1092
- strict(): ZodInterface<
1093
- Shape,
1094
- {
1095
- optional: Params["optional"];
1096
- defaulted: Params["defaulted"];
1097
- extra: {};
1098
- }
1099
- >;
1100
- loose(): ZodInterface<
1101
- Shape,
1102
- {
1103
- optional: Params["optional"];
1104
- defaulted: Params["defaulted"];
1105
- extra: Record<string, unknown>;
1106
- }
1107
- >;
1108
- strip(): ZodInterface<
1109
- Shape,
1110
- {
1111
- optional: Params["optional"];
1112
- defaulted: Params["defaulted"];
1113
- extra: {};
1114
- }
1115
- >;
1116
-
1117
- extend<U extends ZodInterface>(int: U): MergeInterfaces<this, U>;
1118
- extend<U extends core.$ZodLooseShape>(
1119
- shape: U
1120
- ): MergeInterfaces<this, ZodInterface<U, util.InitInterfaceParams<U, {}>>>;
1121
-
1122
- /** @deprecated Use `A.extend(B)` */
1123
- merge<U extends ZodInterface>(incoming: U): MergeInterfaces<this, U>;
1124
-
1125
- pick<const M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1126
- mask: M
1127
- ): ZodInterface<
1128
- util.Flatten<Pick<Shape, keyof Shape & keyof M>>,
1129
- {
1130
- optional: Extract<Params["optional"], keyof M>;
1131
- defaulted: Extract<Params["defaulted"], keyof M>;
1132
- extra: Params["extra"];
1133
- }
1134
- >;
1135
-
1136
- omit<const M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1137
- mask: M
1138
- ): ZodInterface<
1139
- util.Flatten<Omit<Shape, keyof M>>,
1140
- {
1141
- optional: Exclude<Params["optional"], keyof M>;
1142
- defaulted: Exclude<Params["defaulted"], keyof M>;
1143
- extra: Params["extra"];
1144
- }
1145
- >;
1146
-
1147
- partial(): ZodInterfacePartial<this>;
1148
- partial<M extends util.Mask<string & keyof Shape>>(mask: M): ZodInterfacePartial<this, string & keyof M>;
1149
-
1150
- required(): ZodInterfaceRequired<this, string & keyof Shape>;
1151
- required<M extends util.Mask<string & keyof Shape>>(mask: M): ZodInterfaceRequired<this, string & keyof M>;
1152
- }
1153
- export const ZodInterface: core.$constructor<ZodInterface> = /*@__PURE__*/ core.$constructor(
1154
- "ZodInterface",
1155
- (inst, def) => {
1156
- core.$ZodInterface.init(inst, def);
1157
- ZodType.init(inst, def);
1158
- // util.defineLazy(inst._zod, "shape", () => def.shape);
1159
-
1160
- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
1161
- inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
1162
- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
1163
- inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
1164
- inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
1165
- inst.extend = (incoming: any) => {
1166
- if (incoming instanceof core.$ZodInterface) return util.extendObjectLike(inst, incoming);
1167
- return util.extendObjectLike(inst, _interface(incoming));
1168
- };
1169
- inst.merge = (other) => util.mergeObjectLike(inst, other);
1170
- inst.pick = (mask) => util.pick(inst, mask) as any;
1171
- inst.omit = (mask) => util.omit(inst, mask);
1172
- inst.partial = (...args: any[]) => util.partialObjectLike(ZodOptional, inst, args[0]);
1173
- inst.required = (...args: any[]) => util.requiredObjectLike(ZodNonOptional, inst, args[0]);
1174
- }
1175
- );
1176
-
1177
- function _interface<T extends core.$ZodLooseShape>(
1178
- shape: T,
1179
- params?: string | core.$ZodInterfaceParams,
1180
- Class: util.Constructor<ZodInterface> = ZodInterface
1181
- ): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>> {
1182
- const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1183
- const def: core.$ZodInterfaceDef = {
1184
- type: "interface",
1185
- get shape() {
1186
- // return cleaned.value.shape;
1187
- const _shape = cleaned.value.shape;
1188
- util.assignProp(this, "shape", _shape);
1189
- return _shape;
1190
- },
1191
- get optional() {
1192
- return cleaned.value.optional;
1193
- },
1194
- ...util.normalizeParams(params),
1195
- };
1196
- return new Class(def) as any;
1197
- }
1198
- export { _interface as interface };
1199
-
1200
- // strictInterface
1201
-
1202
- export function strictInterface<T extends core.$ZodLooseShape>(
1203
- shape: T,
1204
- params?: string | core.$ZodInterfaceParams
1205
- ): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>> {
1206
- const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1207
- const def: core.$ZodInterfaceDef = {
1208
- type: "interface",
1209
- get shape() {
1210
- // return cleaned.value.shape;
1211
- const _shape = cleaned.value.shape;
1212
- util.assignProp(this, "shape", _shape);
1213
- return _shape;
1214
- },
1215
- get optional() {
1216
- return cleaned.value.optional;
1217
- },
1218
- catchall: never(),
1219
- ...util.normalizeParams(params),
1220
- };
1221
- return new ZodInterface(def) as any;
1222
- }
1223
-
1224
- // looseInterface
1225
-
1226
- export function looseInterface<T extends core.$ZodLooseShape>(
1227
- shape: T,
1228
- params?: string | core.$ZodInterfaceParams
1229
- ): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, Record<string, unknown>>> {
1230
- const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1231
- const def: core.$ZodInterfaceDef = {
1232
- type: "interface",
1233
- get optional() {
1234
- return cleaned.value.optional;
1235
- },
1236
- get shape() {
1237
- // return cleaned.value.shape;
1238
- const _shape = cleaned.value.shape;
1239
- util.assignProp(this, "shape", _shape);
1240
- return _shape;
1241
- },
1242
- catchall: unknown(),
1243
- ...util.normalizeParams(params),
1244
- };
1245
- return new ZodInterface(def) as any;
1246
- }
1247
-
1248
1017
  // ZodObject
1249
1018
  export interface ZodObject<
1250
1019
  // @ts-ignore cast variance
1251
- out Shape extends core.$ZodShape = core.$ZodShape,
1252
- // @ts-ignore cast variance
1253
- Extra extends Record<string, unknown> = Record<string, unknown>,
1020
+ out Shape extends core.$ZodShape = core.$ZodLooseShape,
1021
+ OutExtra extends Record<string, unknown> = Record<string, unknown>,
1022
+ InExtra extends Record<string, unknown> = Record<string, unknown>,
1254
1023
  > extends ZodType {
1255
- _zod: core.$ZodObjectInternals<Shape, Extra>;
1256
-
1024
+ _zod: core.$ZodObjectInternals<Shape, OutExtra, InExtra>;
1257
1025
  shape: Shape;
1258
1026
 
1259
1027
  keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
1028
+ /** Define a schema to validate all unrecognized keys. This overrides the existing strict/loose behavior. */
1260
1029
  catchall<T extends core.$ZodType>(schema: T): ZodObject<Shape, Record<string, T["_zod"]["output"]>>;
1261
1030
 
1262
1031
  /** @deprecated Use `z.looseObject()` or `.loose()` instead. */
1263
1032
  passthrough(): ZodObject<Shape, Record<string, unknown>>;
1264
-
1033
+ /** Consider `z.looseObject(A.shape)` instead */
1265
1034
  loose(): ZodObject<Shape, Record<string, unknown>>;
1266
1035
 
1267
- /** The `z.strictObject()` API is preferred. */
1036
+ /** Consider `z.strictObject(A.shape)` instead */
1268
1037
  strict(): ZodObject<Shape, {}>;
1269
1038
 
1270
- /** @deprecated This is the default behavior. This method call is likely unnecessary. */
1039
+ /** This is the default behavior. This method call is likely unnecessary. */
1271
1040
  strip(): ZodObject<Shape, {}>;
1272
1041
 
1273
- extend<const U extends ZodObject>(schema: U): ZodObject<util.Extend<Shape, U["_zod"]["def"]["shape"]>, Extra>;
1274
- extend<U extends core.$ZodShape>(
1042
+ extend<U extends core.$ZodLooseShape>(
1275
1043
  shape: U
1276
1044
  ): ZodObject<
1277
1045
  util.Extend<Shape, U>,
1278
- Extra // & B['_zod']["extra"]
1046
+ OutExtra,
1047
+ InExtra // & B['_zod']["extra"]
1279
1048
  >;
1280
1049
 
1281
- // merge
1282
- /** @deprecated Use `A.extend(B)` */
1283
- merge<U extends ZodObject<any, any>>(
1050
+ /**
1051
+ * @deprecated Use destructuring to merge the shapes:
1052
+ *
1053
+ * ```ts
1054
+ * z.object({
1055
+ * ...A.shape,
1056
+ * ...B.shape
1057
+ * });
1058
+ * ```
1059
+ */
1060
+ merge<U extends ZodObject>(
1284
1061
  other: U
1285
- ): ZodObject<util.Flatten<util.Extend<Shape, U["_zod"]["def"]["shape"]>>, Extra>;
1062
+ ): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["outextra"], U["_zod"]["inextra"]>;
1063
+ /**
1064
+ * @deprecated Use destructuring to merge the shapes:
1065
+ *
1066
+ * ```ts
1067
+ * z.object({
1068
+ * ...A.shape,
1069
+ * ...B.shape
1070
+ * });
1071
+ * ```
1072
+ */
1286
1073
 
1287
1074
  pick<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1288
1075
  mask: M
1289
- ): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Extra>;
1076
+ ): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, OutExtra, InExtra>;
1290
1077
 
1291
1078
  omit<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1292
1079
  mask: M
1293
- ): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Extra>;
1080
+ ): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, OutExtra, InExtra>;
1294
1081
 
1295
1082
  partial(): ZodObject<
1296
1083
  {
1297
1084
  [k in keyof Shape]: ZodOptional<Shape[k]>;
1298
1085
  },
1299
- Extra
1086
+ OutExtra,
1087
+ InExtra
1300
1088
  >;
1301
1089
  partial<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1302
1090
  mask: M
@@ -1304,7 +1092,8 @@ export interface ZodObject<
1304
1092
  {
1305
1093
  [k in keyof Shape]: k extends keyof M ? ZodOptional<Shape[k]> : Shape[k];
1306
1094
  },
1307
- Extra
1095
+ OutExtra,
1096
+ InExtra
1308
1097
  >;
1309
1098
 
1310
1099
  // required
@@ -1312,7 +1101,8 @@ export interface ZodObject<
1312
1101
  {
1313
1102
  [k in keyof Shape]: ZodNonOptional<Shape[k]>;
1314
1103
  },
1315
- Extra
1104
+ OutExtra,
1105
+ InExtra
1316
1106
  >;
1317
1107
  required<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1318
1108
  mask: M
@@ -1320,14 +1110,18 @@ export interface ZodObject<
1320
1110
  {
1321
1111
  [k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
1322
1112
  },
1323
- Extra
1113
+ OutExtra,
1114
+ InExtra
1324
1115
  >;
1325
1116
  }
1117
+
1326
1118
  export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
1327
1119
  core.$ZodObject.init(inst, def);
1328
1120
  ZodType.init(inst, def);
1329
1121
 
1330
- inst.shape = def.shape;
1122
+ util.defineLazy(inst, "shape", () => {
1123
+ return Object.fromEntries(Object.entries(inst._zod.def.shape));
1124
+ });
1331
1125
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)) as any;
1332
1126
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
1333
1127
  inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
@@ -1337,25 +1131,27 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
1337
1131
  inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
1338
1132
 
1339
1133
  inst.extend = (incoming: any) => {
1340
- if (incoming instanceof ZodObject) return util.extendObjectLike(inst, incoming);
1341
- return util.extendObjectLike(inst, object(incoming));
1134
+ return util.extend(inst, incoming);
1342
1135
  };
1343
- inst.merge = (other) => util.mergeObjectLike(inst, other);
1136
+ inst.merge = (other) => util.merge(inst, other);
1344
1137
  inst.pick = (mask) => util.pick(inst, mask);
1345
1138
  inst.omit = (mask) => util.omit(inst, mask);
1346
- inst.partial = (...args: any[]) => util.partialObjectLike(ZodOptional, inst, args[0] as object);
1347
- inst.required = (...args: any[]) => util.requiredObjectLike(ZodNonOptional, inst, args[0] as object);
1139
+ inst.partial = (...args: any[]) => util.partial(ZodOptional, inst, args[0] as object);
1140
+ inst.required = (...args: any[]) => util.required(ZodNonOptional, inst, args[0] as object);
1348
1141
  });
1349
- export function object<T extends core.$ZodShape = Record<never, core.$ZodType>>(
1142
+
1143
+ export function object<T extends core.$ZodLooseShape = Record<never, core.$ZodType>>(
1350
1144
  shape?: T,
1351
- params?: string | core.$ZodObjectLikeParams
1352
- ): ZodObject<T, {}> {
1145
+ params?: string | core.$ZodObjectParams
1146
+ ): ZodObject<util.Writeable<T> & {}, {}, {}> {
1353
1147
  const def: core.$ZodObjectDef = {
1354
1148
  type: "object",
1355
- shape: shape ?? {},
1356
- get optional() {
1357
- return util.optionalObjectKeys(shape ?? {});
1149
+
1150
+ get shape() {
1151
+ util.assignProp(this, "shape", { ...shape });
1152
+ return this.shape;
1358
1153
  },
1154
+
1359
1155
  ...util.normalizeParams(params),
1360
1156
  };
1361
1157
  return new ZodObject(def) as any;
@@ -1363,230 +1159,43 @@ export function object<T extends core.$ZodShape = Record<never, core.$ZodType>>(
1363
1159
 
1364
1160
  // strictObject
1365
1161
 
1366
- export function strictObject<T extends core.$ZodShape>(
1162
+ export function strictObject<T extends core.$ZodLooseShape>(
1367
1163
  shape: T,
1368
1164
  params?: string | core.$ZodObjectParams
1369
- ): ZodObject<T, {}> {
1165
+ ): ZodObject<T, {}, {}> {
1370
1166
  return new ZodObject({
1371
1167
  type: "object",
1372
- shape: shape as core.$ZodShape,
1373
- get optional() {
1374
- return util.optionalObjectKeys(shape);
1168
+
1169
+ get shape() {
1170
+ util.assignProp(this, "shape", { ...shape });
1171
+ return this.shape;
1375
1172
  },
1173
+
1376
1174
  catchall: never(),
1377
1175
  ...util.normalizeParams(params),
1378
1176
  }) as any;
1379
1177
  }
1380
1178
 
1381
1179
  // looseObject
1382
-
1383
- export function looseObject<T extends core.$ZodShape>(
1180
+ export function looseObject<T extends core.$ZodLooseShape>(
1384
1181
  shape: T,
1385
1182
  params?: string | core.$ZodObjectParams
1386
- ): ZodObject<T, { [k: string]: unknown }> {
1183
+ ): ZodObject<T, { [k: string]: unknown }, { [k: string]: unknown }> {
1387
1184
  return new ZodObject({
1388
1185
  type: "object",
1389
- shape: shape as core.$ZodShape,
1390
- get optional() {
1391
- return util.optionalObjectKeys(shape);
1186
+
1187
+ get shape() {
1188
+ util.assignProp(this, "shape", { ...shape });
1189
+ return this.shape;
1392
1190
  },
1191
+
1393
1192
  catchall: unknown(),
1394
1193
  ...util.normalizeParams(params),
1395
1194
  }) as any;
1396
1195
  }
1397
1196
 
1398
- // object methods
1399
- export function extend<T extends ZodInterface, U extends ZodInterface>(
1400
- a: T,
1401
- b: U
1402
- ): ZodInterface<util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>, util.MergeInterfaceParams<T, U>>;
1403
- export function extend<T extends ZodObject, U extends ZodObject>(
1404
- a: T,
1405
- b: U
1406
- ): ZodObject<
1407
- util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>,
1408
- U["_zod"]["extra"] & T["_zod"]["extra"]
1409
- >;
1410
- export function extend<T extends ZodObjectLike, U extends core.$ZodLooseShape>(
1411
- schema: T,
1412
- shape: U
1413
- ): T extends ZodInterface<infer TShape, infer TParams>
1414
- ? ZodInterface<util.ExtendInterfaceShape<TShape, U>, util.ExtendInterfaceParams<ZodInterface<TShape, TParams>, U>>
1415
- : ZodObject<util.Extend<T["_zod"]["def"]["shape"], U>, T["_zod"]["extra"]>;
1416
- export function extend(schema: ZodObjectLike, shape: core.$ZodShape): ZodObjectLike {
1417
- if (shape instanceof core.$ZodType) return util.mergeObjectLike(schema, shape as any);
1418
- if (schema instanceof ZodInterface) {
1419
- return util.mergeObjectLike(schema, _interface(shape));
1420
- }
1421
- if (schema instanceof ZodObject) return util.mergeObjectLike(schema, object(shape));
1422
- return util.extend(schema, shape);
1423
- }
1424
-
1425
- export function merge<T extends ZodObjectLike, U extends core.$ZodLooseShape>(
1426
- schema: T,
1427
- shape: U
1428
- ): T["_zod"]["def"]["type"] extends "interface"
1429
- ? // T extends ZodInterface
1430
- ZodInterface<
1431
- util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>,
1432
- {
1433
- extra: T["_zod"]["extra"] & U["_zod"]["extra"];
1434
- optional: Exclude<T["_zod"]["optional"], keyof U["_zod"]["def"]["shape"]> | U["_zod"]["optional"];
1435
- defaulted: Exclude<T["_zod"]["defaulted"], keyof U["_zod"]["def"]["shape"]> | U["_zod"]["defaulted"];
1436
- }
1437
- >
1438
- : ZodObject<util.Extend<T["_zod"]["def"]["shape"], U>, T["_zod"]["extra"]>;
1439
- export function merge(a: ZodObjectLike, b: ZodObjectLike): ZodObjectLike {
1440
- return util.mergeObjectLike(a, b);
1441
- }
1442
-
1443
- // .pick
1444
- export function pick<T extends ZodObjectLike, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(
1445
- schema: T,
1446
- mask: M
1447
- ): T["_zod"]["def"]["type"] extends "interface"
1448
- ? ZodInterface<
1449
- util.Flatten<Pick<T["_zod"]["def"]["shape"], keyof T["_zod"]["def"]["shape"] & keyof M>>,
1450
- {
1451
- optional: Extract<T["_zod"]["optional"], keyof M>;
1452
- defaulted: Extract<T["_zod"]["defaulted"], keyof M>;
1453
- extra: T["_zod"]["extra"];
1454
- }
1455
- >
1456
- : ZodObject<
1457
- util.Flatten<Pick<T["_zod"]["def"]["shape"], keyof T["_zod"]["def"]["shape"] & keyof M>>,
1458
- T["_zod"]["extra"]
1459
- >;
1460
- export function pick(schema: ZodObjectLike, mask: object) {
1461
- // const picked = util.pick(schema, mask);
1462
- return util.pick(schema, mask);
1463
- }
1464
-
1465
- // .omit
1466
- export function omit<
1467
- T extends ZodObjectLike,
1468
- const M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>,
1469
- >(
1470
- schema: T,
1471
- mask: M
1472
- ): T["_zod"]["def"]["type"] extends "interface"
1473
- ? ZodInterface<
1474
- util.Flatten<Omit<T["_zod"]["def"]["shape"], keyof M>>,
1475
- {
1476
- optional: Exclude<T["_zod"]["optional"], keyof M>;
1477
- defaulted: Exclude<T["_zod"]["defaulted"], keyof M>;
1478
- extra: T["_zod"]["extra"];
1479
- }
1480
- >
1481
- : ZodObject<util.Flatten<Omit<T["_zod"]["def"]["shape"], keyof M>>, T["_zod"]["extra"]>;
1482
-
1483
- export function omit(schema: ZodObjectLike, mask: object) {
1484
- return util.omit(schema, mask);
1485
- }
1486
-
1487
- export function partial<T extends ZodObjectLike>(
1488
- schema: T
1489
- ): T["_zod"]["def"]["type"] extends "interface"
1490
- ? ZodInterface<
1491
- // T['_zod']["shape"],
1492
- {
1493
- [k in keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1494
- },
1495
- {
1496
- optional: string & keyof T["_zod"]["def"]["shape"];
1497
- defaulted: never;
1498
- extra: T["_zod"]["extra"];
1499
- }
1500
- >
1501
- : ZodObject<
1502
- {
1503
- [k in keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1504
- },
1505
- T["_zod"]["extra"]
1506
- >;
1507
- export function partial<T extends ZodObjectLike, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(
1508
- schema: T,
1509
- mask: M
1510
- ): T["_zod"]["def"]["type"] extends "interface"
1511
- ? ZodInterface<
1512
- util.Extend<
1513
- T["_zod"]["def"]["shape"],
1514
- {
1515
- [k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1516
- }
1517
- >,
1518
- {
1519
- optional: string & (T["_zod"]["optional"] | keyof M);
1520
- defaulted: T["_zod"]["defaulted"];
1521
- extra: T["_zod"]["extra"];
1522
- }
1523
- >
1524
- : ZodObject<
1525
- {
1526
- [k in keyof T["_zod"]["def"]["shape"]]: k extends keyof M
1527
- ? ZodOptional<T["_zod"]["def"]["shape"][k]>
1528
- : T["_zod"]["def"]["shape"][k];
1529
- },
1530
- T["_zod"]["extra"]
1531
- >;
1532
-
1533
- export function partial(schema: ZodObjectLike, mask?: object): ZodObjectLike {
1534
- return util.partialObjectLike(ZodOptional, schema, mask);
1535
- }
1536
-
1537
- // .required
1538
- export function required<T extends { _subtype: "object" } & ZodObject>(
1539
- schema: T
1540
- ): ZodObject<{
1541
- [k in keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1542
- }>;
1543
- export function required<
1544
- T extends { _subtype: "object" } & ZodObject,
1545
- M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>,
1546
- >(
1547
- schema: T,
1548
- mask: M
1549
- ): ZodObject<
1550
- util.Extend<
1551
- T["_zod"]["def"]["shape"],
1552
- {
1553
- [k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1554
- }
1555
- >
1556
- >;
1557
- export function required<T extends { _subtype: "interface" } & ZodInterface>(
1558
- schema: T
1559
- ): ZodInterface<
1560
- {
1561
- [k in keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1562
- },
1563
- {
1564
- optional: never;
1565
- defaulted: T["_zod"]["defaulted"];
1566
- extra: T["_zod"]["extra"];
1567
- }
1568
- >;
1569
- export function required<
1570
- T extends { _subtype: "interface" } & ZodInterface,
1571
- M extends util.Mask<keyof T["_zod"]["output"]>,
1572
- >(
1573
- schema: T,
1574
- mask: M
1575
- ): ZodInterface<
1576
- util.Extend<
1577
- T["_zod"]["def"]["shape"],
1578
- {
1579
- [k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1580
- }
1581
- >,
1582
- {
1583
- optional: Exclude<T["_zod"]["optional"], keyof M>;
1584
- defaulted: T["_zod"]["defaulted"];
1585
- extra: T["_zod"]["extra"];
1586
- }
1587
- >;
1588
- export function required(schema: ZodObjectLike, mask?: object): ZodObjectLike {
1589
- return util.requiredObjectLike(ZodNonOptional, schema, mask);
1197
+ export function partial<T>(shape: T): Partial<T> {
1198
+ return shape;
1590
1199
  }
1591
1200
 
1592
1201
  // ZodUnion