You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there! We're swapping to zod in our library for validation and we have the following use case:
// some-dependencyenumSomething{X,Y,Z}
We're using this numeric enum from our dependency (which has more like 14 available members), and we happen to want, say, 6 of them as allowed values to a record field.
My instinct was to use z.nativeEnum(Something).extract(...), but I was surprised to learn it doesn't exist. My next idea was to do what I thought was the next most-correct thing, which is z.enum([Something.X, Something.Y, ...]), but I was quickly reminded it only supports strings (fair).
I think ultimately though, it'd be ideal if "native enums" supported extract & exclude. I'd be willing to try to implement this, just figured I'd make an issue first in case there's a clear-cut sort of blocker for something like this.
The text was updated successfully, but these errors were encountered:
Hey there! We're swapping to zod in our library for validation and we have the following use case:
We're using this numeric enum from our dependency (which has more like 14 available members), and we happen to want, say, 6 of them as allowed values to a record field.
My instinct was to use
z.nativeEnum(Something).extract(...)
, but I was surprised to learn it doesn't exist. My next idea was to do what I thought was the next most-correct thing, which isz.enum([Something.X, Something.Y, ...])
, but I was quickly reminded it only supports strings (fair).Which leaves me with using literals. #2686 (comment) would be of big help already, since I ended up having to do something like this: https://github.com/discordjs/discord.js/blob/6d44a77180fc52e6b87278b8054c54cb3a501600/packages/builders/src/interactions/slashCommands/Assertions.ts#L61-L75
I think ultimately though, it'd be ideal if "native enums" supported extract & exclude. I'd be willing to try to implement this, just figured I'd make an issue first in case there's a clear-cut sort of blocker for something like this.
The text was updated successfully, but these errors were encountered: