From 0c0e49517e4dfa666017d7fd863c4c18c2bf7987 Mon Sep 17 00:00:00 2001 From: Peramanathan Sathyamoorthy Date: Thu, 15 Dec 2022 12:56:18 +0100 Subject: [PATCH 1/2] change the chaining order of nullish method Solves https://github.com/colinhacks/zod/discussions/1565 --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index ef27ec585..ce54bc838 100644 --- a/src/types.ts +++ b/src/types.ts @@ -396,7 +396,7 @@ export abstract class ZodType< return ZodNullable.create(this) as any; } nullish(): ZodNullable> { - return this.optional().nullable(); + return this.nullable().optional(); } array(): ZodArray { return ZodArray.create(this); From 9f7dbae68a846cc9f81b05bf62479edca7ae5ee7 Mon Sep 17 00:00:00 2001 From: Jacob Weisenburger <31667350+JacobWeisenburger@users.noreply.github.com> Date: Sat, 31 Dec 2022 09:24:16 -0600 Subject: [PATCH 2/2] Changed the return type to match --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index ce54bc838..e371c789a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -395,7 +395,7 @@ export abstract class ZodType< nullable(): ZodNullable { return ZodNullable.create(this) as any; } - nullish(): ZodNullable> { + nullish(): ZodOptional> { return this.nullable().optional(); } array(): ZodArray {