enum to string (and number) literals keeping the opacity #38658
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
enum typing, enum valueOf, enum string literal
Suggestion
The values of the strings enum are by design opaque it might however be useful to have a way to type them out of the enum.
This is what we have now:
My feature request is to type the
valueOf()
using string literals and number "literals"Use Cases
Examples
Note: What I do not know is how this custom type could use a generic for the enum, as
<T extends enum>
is invalid. An enum is a bit weird in TS as it both represents a type and an objectChecklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: