-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Allowing you to check membership of an enum #35215
Labels
Duplicate
An existing issue was already created
Comments
Ah yes, I wasn't thinking about it from that perspective, making |
Yep, any alternate to those would be out of scope anyway. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suggestion
I'd like to write a function to if a value is a member of an enum.
Use Cases
This is useful anytime you have external data you want to validate is a member of an enum, such as loading data from a network or a config file.
Examples
This code used to work in older versions of TypeScript, but with the stricter definitions for
Object.values
the compiler now (correctly) says that the return value ofObject.values
isEnvironment[]
, and so I can't check if an enum includes a string without casting in some way:Alternatively I tried making a generic enum membership function so I can limit my casting to a single place, but that didn't work very well. My TypeScript foo appears to be lacking.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: