diff --git a/deno/lib/__tests__/description.test.ts b/deno/lib/__tests__/description.test.ts index 63015eab9..b19018a5c 100644 --- a/deno/lib/__tests__/description.test.ts +++ b/deno/lib/__tests__/description.test.ts @@ -26,3 +26,11 @@ test("description should carry over to chained schemas", () => { description ); }); + +test("description should not carry over to chained array schema", () => { + const schema = z.string().describe(description) + + expect(schema.description).toEqual(description); + expect(schema.array().description).toEqual(undefined); + expect(z.array(schema).description).toEqual(undefined); +}) diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 1fed75de2..3bb8b65e0 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -434,7 +434,7 @@ export abstract class ZodType< return this.nullable().optional(); } array(): ZodArray { - return ZodArray.create(this, this._def); + return ZodArray.create(this); } promise(): ZodPromise { return ZodPromise.create(this, this._def); diff --git a/src/__tests__/description.test.ts b/src/__tests__/description.test.ts index 5a8d73dc8..68187238c 100644 --- a/src/__tests__/description.test.ts +++ b/src/__tests__/description.test.ts @@ -25,3 +25,11 @@ test("description should carry over to chained schemas", () => { description ); }); + +test("description should not carry over to chained array schema", () => { + const schema = z.string().describe(description) + + expect(schema.description).toEqual(description); + expect(schema.array().description).toEqual(undefined); + expect(z.array(schema).description).toEqual(undefined); +}) diff --git a/src/types.ts b/src/types.ts index 24e12299e..5f8c65d04 100644 --- a/src/types.ts +++ b/src/types.ts @@ -434,7 +434,7 @@ export abstract class ZodType< return this.nullable().optional(); } array(): ZodArray { - return ZodArray.create(this, this._def); + return ZodArray.create(this); } promise(): ZodPromise { return ZodPromise.create(this, this._def);