added label in zod type Close #1767 #1902
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #1767
as you asked i, have made a working draft #1902
it's only working for
z.object({ first: z.string({ label: "First Name", }).min(3), })
at the moment but you will get an idea of how this is gonna + I have also added labeled messages in "en.ts" (all the messages are not good)In answering your question about DX if we add labeled errors I think it will be great. when I used Zod for the first time this was a single feature I thought must exist to make this library complete
Without Labeled error
we cant send it to a client or show it to a user directly we have to add customized errors everywhere even though if its a really simple message like "First name is Required" since "Invalid input" cant be sent
just to add really simple messages it becomes mandatory to include a "message" for every check
With Labeled Errors
if the label is passed all those messages can be removed and that error can be passed directly to the client/user
even if they want to customize the message further they can do so
if you think this feature is worth added do you mind assigning it to me