Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow .extract/.exclude for nativeEnums #3747

Open
didinele opened this issue Sep 8, 2024 · 0 comments
Open

Allow .extract/.exclude for nativeEnums #3747

didinele opened this issue Sep 8, 2024 · 0 comments

Comments

@didinele
Copy link

didinele commented Sep 8, 2024

Hey there! We're swapping to zod in our library for validation and we have the following use case:

// some-dependency
enum Something {
  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).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant