We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to use an enum as a generic?
Say that I have an enum, and I want to set the color for each enum value.
enum Status { ACTIVE, PENDING } enumColors(Status, { [Status.ACTIVE]: 'red' })
Is there a way to do this dynamically based on a generic for the enum?
I tried this:
declare function enumColors<Key extends string, Value extends string, Enum extends { [key in Key]: Value }>( enumeration: Enum, colors: { [key in Key]?: string } )
Playground link here.
This is the error I see:
The text was updated successfully, but these errors were encountered:
Ah, the solution was to use the value, not key:
declare function enumColors<Key extends string, Value extends string, Enum extends { [key in Key]: Value }>( enumeration: Enum, colors: { [value in Value]?: string } // Value, not Key )
Sorry, something went wrong.
No branches or pull requests
馃崺 Feature Request
Is there a way to use an enum as a generic?
Describe the solution you'd like
Say that I have an enum, and I want to set the color for each enum value.
Is there a way to do this dynamically based on a generic for the enum?
Describe alternatives you've considered
I tried this:
Playground link here.
Teachability, Documentation, Adoption, Migration Strategy
This is the error I see:
The text was updated successfully, but these errors were encountered: