From c4d4e494227aadc752d4d5a5a317ec16bb6f5a45 Mon Sep 17 00:00:00 2001 From: Simon Proper <62900484+SimonProper@users.noreply.github.com> Date: Mon, 27 Feb 2023 01:19:22 +0100 Subject: [PATCH] Update ERROR_HANDLING.md (#2022) Makes the example more consistent with the provided explanations above as well as increasing the clarity of the example. Can for example be easy to miss that you need to name the error map variable exactly the same as the property field when passing it this way. --- ERROR_HANDLING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ERROR_HANDLING.md b/ERROR_HANDLING.md index 7c0604354..5bd9de3b0 100644 --- a/ERROR_HANDLING.md +++ b/ERROR_HANDLING.md @@ -232,7 +232,7 @@ Let's look at a practical example of of customized error map: ```ts import * as z from "zod"; -const errorMap: z.ZodErrorMap = (error, ctx) => { +const customErrorMap: z.ZodErrorMap = (error, ctx) => { /* This is where you override the various error codes */ @@ -257,7 +257,7 @@ const errorMap: z.ZodErrorMap = (error, ctx) => { return { message: ctx.defaultError }; }; -z.string().parse(12, { errorMap }); +z.string().parse(12, { errorMap: customErrorMap }); /* throws: ZodError {