microsoft / microsoft/TypeScript
Extending string-based enums
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Before string based enums, many would fall back to objects. Using objects also allows extending of types. For example:
const BasicEvents = {
Start: "Start",
Finish: "Finish"
};
const AdvEvents = {
...BasicEvents,
Pause: "Pause",
Resume: "Resume"
};
When switching over to string enums, it"s impossible to achieve this without re-defining the enum.
I would be very useful to be able to do something like this:
enum BasicEvents {
Start = "Start",
Finish = "Finish"
};
// extend enum using "extends" keyword
enum AdvEvents extends BasicEvents {
Pause = "Pause",
Resume = "Resume"
};
Considering that the produced enums are objects, this won"t be too horrible either:
// extend enum using spread
enum AdvEvents {
...BasicEvents,
Pause = "Pause",
Resume = "Resume"
};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the string-enum and object-spread examples in the issue, then examine how enum syntax and emitted JavaScript are currently defined. Establish the intended inheritance or spread semantics, including type-checking and generated-object behavior, and validate that the proposal is compatible with existing enums.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100