Repository navigation
Extends current enum to add new cases #5
Replies: 2 comments
|
Enums in Python allow a restricted form of subclassing, where you can define methods on a base (or mix-in) class. You cannot, however, extend a base enum to add new enum members. In C#, you cannot extend an enum, but you can use extension methods to add related methods. In TS, you cannot extend an enum via subclassing, but we do support declaration merging as long as the enums are in the same file (which I am not advocating for this proposal). I don't believe subclassing enums should be considered for this proposal. |
|
Briefly: I'm in favor of enabling some kind of re-use of enum values between enums, but I think it sets up the wrong expectations to present it as "extending" the enum, and to use the Here's why:
The README already says that the enum is "non-extensible". This is the right default; sum types like enums should be non-extensible, because that's how you get value from matching/destructuring them. The second connotation of |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In microsoft/TypeScript#17592 this feature is required
Problems
This feature conflicts with Inline-able(#4) and hoistable declaration (#18).
It requires adding a initialize stage to "throw" when the extended
enumis not a valid one.It will trigger user code when the extended value is
getterorProxy.Should we support this use case?
All reactions