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
Maybe even include the Omit operator so we could technically omit a value when extending an enum.
π Motivating Example
It would simplify working with enums greatly. In many projects I've seen duplicated enum values, some weird work-around to make them work without duplicating values or I've even heard some people say straight up don't use them since they're not as powerfull as they are in other language.
If I wanted color to looks something like this but still keep a PrimaryColor enum (to give better typing to places where it can only be a PrimaryColor)
enum Colors { GREEN = 'green', PURPLE = 'purple', RED = 'red', YELLOW = 'yellow', BLUE = 'blue' }
I would either need to duplicate values within the enum (which isn't great) or do something unusual like this :
type Colors = PrimaryColors | OtherColors;
const Colors = {...PrimaryColors , ...OtherColors};
let color: Colors = Colors.RED
I'm not the only one which has ran into this issue (see : https://stackoverflow.com/questions/52857698/extending-enum-in-typescript
). Enum kinda feel like pointless when you'd be better declaring Objects as const which is unfortunate IMO since they have syntax highlighthing and are usually easier to recognize.
The text was updated successfully, but these errors were encountered:
Suggestion
Extending enums
π Search Terms
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
I would like to be able to extend enums from other enums. something with a syntax like this ish..
Maybe even include the Omit operator so we could technically omit a value when extending an enum.
π Motivating Example
It would simplify working with enums greatly. In many projects I've seen duplicated enum values, some weird work-around to make them work without duplicating values or I've even heard some people say straight up don't use them since they're not as powerfull as they are in other language.
π» Use Cases
If I take the example I mentionned on top eg :
If I wanted color to looks something like this but still keep a PrimaryColor enum (to give better typing to places where it can only be a PrimaryColor)
I would either need to duplicate values within the enum (which isn't great) or do something unusual like this :
I'm not the only one which has ran into this issue (see : https://stackoverflow.com/questions/52857698/extending-enum-in-typescript
). Enum kinda feel like pointless when you'd be better declaring Objects as const which is unfortunate IMO since they have syntax highlighthing and are usually easier to recognize.
The text was updated successfully, but these errors were encountered: