microsoft / microsoft/TypeScript
String Enum Initializer
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
String Enum Initializer
A more typesafe and succinct way of defining enum types that compile to strings
Search Terms
enum, string, string enum
default value
initializer
infer
Proposal
It seems like you should be able to specify that you are using a string enum, and then you'd only have to write out the 'value' once, and it would be automatically made into a string matching the enum code.
enum<string> Action {
LOAD_PROFILE,
ADD_TASK,
REMOVE_TASK
}
or
enum Action: string {
LOAD_PROFILE,
ADD_TASK,
REMOVE_TASK
}
instead of
enum Action {
LOAD_PROFILE = "LOAD_PROFILE",
ADD_TASK = "ADD_TASK",
REMOVE_TASK = "REMOVE_TASK"
}
Thanks for all the great work!
EDIT
Recently updated to reflect variations proposed by @imcotton here and @lostpebble here; as well as search terms proposed by @KennethKo (#36319) and @garrettmaring (#33015)
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
The proposal gives example enum syntax and the desired inferred string values, but names no implementation files, tests, or entry points. Start by locating the compiler's enum parsing, checking, and emit paths, then identify existing enum tests. Done means a supported string-enum initializer has the proposed syntax and emits the matching string values without requiring repeated assignments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100