microsoft / microsoft/TypeScript
String Enum Initializer
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La proposta fornisce esempi della sintassi enum e dei valori stringa inferiti desiderati, ma non indica file di implementazione, test o punti di ingresso. Inizia individuando i percorsi di parsing, controllo ed emissione degli enum del compilatore, quindi identifica i test enum esistenti. Il lavoro è completato quando un inizializzatore di string-enum supportato utilizza la sintassi proposta ed emette i valori stringa corrispondenti senza richiedere assegnazioni ripetute.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100