Skip to content

Commit 028ca36

Browse files
committed
Add unwrap to ZodArray
1 parent 6bcc923 commit 028ca36

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/zod/src/v4/classic/schemas.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ export interface ZodArray<T extends core.$ZodType = core.$ZodType> extends ZodTy
10151015
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
10161016
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
10171017
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
1018+
1019+
unwrap(): T;
10181020
}
10191021
export const ZodArray: core.$constructor<ZodArray> = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def) => {
10201022
core.$ZodArray.init(inst, def);
@@ -1025,6 +1027,8 @@ export const ZodArray: core.$constructor<ZodArray> = /*@__PURE__*/ core.$constru
10251027
inst.nonempty = (params) => inst.check(checks.minLength(1, params));
10261028
inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
10271029
inst.length = (len, params) => inst.check(checks.length(len, params));
1030+
1031+
inst.unwrap = () => inst.element;
10281032
});
10291033

10301034
export function array<T extends core.$ZodType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T> {

play.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ const result = z
1111
});
1212

1313
console.log(JSON.stringify(result.error!.issues, null, 2));
14+
15+
z.array(z.string()).def.element;

0 commit comments

Comments
 (0)