zod
zod copied to clipboard
update makeIssue to support the force parameter returned from setErrorMap and allow Custom Message Translations
Now you can define error messages at the schema level (like a translation key), and use setErrorMap like this to lookup the translation.
Returning force: true will prevent this message of being overwritten by the schema message. This allow to create and return more custom translations for messages.
// Translation logic ex. // error.message is the one defined at schema level; that now you can use it as the translation key
Usage:
z.setErrorMap((error, ctx) => {
const message = getTranslatedMessageForKey(error.message);
return { message, force: true };
});
Deploy Preview for guileless-rolypoly-866f8a ready!
Built without sensitive environment variables
Name | Link |
---|---|
Latest commit | 800b31cbcee66199c6ecc5c4b82309385b86f52d |
Latest deploy log | https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/654d20462c2d550008f6e6de |
Deploy Preview | https://deploy-preview-2950--guileless-rolypoly-866f8a.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
I have a specific use case where this option would be really useful and kindly ask the maintainers of this project to consider merging this PR soon.
Thanks for this PR. The error map system is being totally rewritten for Zod 4 so I'm afraid there's little point in modifying this API now. I'll keep this use case under consideration.