From 37551462f4a534f86e6190aafea1747b010eca7a Mon Sep 17 00:00:00 2001 From: EthanBehrends Date: Mon, 9 Dec 2024 18:18:59 -0800 Subject: [PATCH] Remove createParams cascade from .array() (#3530) --- deno/lib/__tests__/description.test.ts | 8 ++++++++ deno/lib/types.ts | 2 +- src/__tests__/description.test.ts | 8 ++++++++ src/types.ts | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) 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);