diff --git a/deno/lib/README.md b/deno/lib/README.md index 2b6c41743..856f8c633 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -604,7 +604,7 @@ dateSchema.safeParse(new Date("1/12/22")); // success: true dateSchema.safeParse("2022-01-12T00:00:00.000Z"); // success: true ``` -## Zod enums- +## Zod enums ```ts const FishEnum = z.enum(["Salmon", "Tuna", "Trout"]); diff --git a/deno/lib/__tests__/refine.test.ts b/deno/lib/__tests__/refine.test.ts index b5e83c27f..b0cee3a6b 100644 --- a/deno/lib/__tests__/refine.test.ts +++ b/deno/lib/__tests__/refine.test.ts @@ -54,10 +54,14 @@ test("refinement type guard", () => { const validationSchema = z.object({ a: z.string().refine((s): s is "a" => s === "a"), }); + type Input = z.input; type Schema = z.infer; + util.assertEqual<"a", Input["a"]>(false); + util.assertEqual(true); + util.assertEqual<"a", Schema["a"]>(true); - util.assertEqual<"string", Schema["a"]>(false); + util.assertEqual(false); }); test("refinement Promise", async () => { diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 13f6eaaa9..73500cb2f 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -268,7 +268,7 @@ export abstract class ZodType< refine( check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams) - ): ZodEffects; + ): ZodEffects; refine( check: (arg: Output) => unknown | Promise, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams) @@ -315,7 +315,7 @@ export abstract class ZodType< refinement( check: (arg: Output) => arg is RefinedOutput, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData) - ): ZodEffects; + ): ZodEffects; refinement( check: (arg: Output) => boolean, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData) diff --git a/src/__tests__/refine.test.ts b/src/__tests__/refine.test.ts index 52f484c14..1fd8022e1 100644 --- a/src/__tests__/refine.test.ts +++ b/src/__tests__/refine.test.ts @@ -53,10 +53,14 @@ test("refinement type guard", () => { const validationSchema = z.object({ a: z.string().refine((s): s is "a" => s === "a"), }); + type Input = z.input; type Schema = z.infer; + util.assertEqual<"a", Input["a"]>(false); + util.assertEqual(true); + util.assertEqual<"a", Schema["a"]>(true); - util.assertEqual<"string", Schema["a"]>(false); + util.assertEqual(false); }); test("refinement Promise", async () => { diff --git a/src/types.ts b/src/types.ts index 1d4badcdd..cd194ee1d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -268,7 +268,7 @@ export abstract class ZodType< refine( check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams) - ): ZodEffects; + ): ZodEffects; refine( check: (arg: Output) => unknown | Promise, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams) @@ -315,7 +315,7 @@ export abstract class ZodType< refinement( check: (arg: Output) => arg is RefinedOutput, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData) - ): ZodEffects; + ): ZodEffects; refinement( check: (arg: Output) => boolean, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)