TypeScript union type of all "type" properties? #1396
Replies: 2 comments 1 reply
-
|
Valibot doesn't provide a built-in union type or enum of all standard issue "type" strings across all schemas (like Zod's ZodIssueCode). Each issue's type is a string literal corresponding to the validation function that failed (for example, "min_length", "array", "email"). The only way to get a union of all issue types in your codebase is to manually combine v.InferIssue for each schema you use, including nested schemas, and then extract the "type" property from that union. There isn't a more automated or centralized approach documented at this time reference reference. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
Hey 👋 sorry for the late replay. If this is still relevant... Can you provide pseudo code on what you expect Valibot to provide to make your life easier. I need to see code and understand the use case better to make a decision. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my codebase, I map a combination of form fields and issue types to their corresponding error messages, e.g.
("userName" + "min_length") => "The user name is too short".In zod v3, ZodIssueCode is available. I'm searching for an equivalent in valibot.
The issue types seem to be literals (e.g.
min_valuehere), so I can only access them for concrete schemas viav.InferIssue. This is more concise than a type containing all issue type strings, but also means that I need to explicitly include nested schemas like this:Is there a convenient way to have all standard issue types represented as a union type?
Beta Was this translation helpful? Give feedback.
All reactions