From ab281429b5ee3cce0259b8ceb24c86af4f4a6444 Mon Sep 17 00:00:00 2001 From: Simon Proper <62900484+SimonProper@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:28:15 +0100 Subject: [PATCH] Update ERROR_HANDLING.md 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 f2806f4ff..a9c173888 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 {