microsoft / microsoft/TypeScript
Flexibility of template literal types for enums
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Search Terms
template literal type enum permutations
Suggestion
Typescript 4.1 brought template literal types, which make it simple to express all the possibilities of permutations of unions of string types concatenated together. It would be cool if there was some equivalent syntax for expressing enum key/value pairs with the same level of expressivity that template literal types provide.
Use Cases
However, my codebase right now uses enums for these kinds of string types, so if I want to express a bunch of permutations of possible values with an enum, I can't really leverage template literal types in this case.
Examples
this is just some syntax I'm making up, I don't know how this would work especially for dealing with keys and values separately:
enum Color {
RED,
BLUE
}
enum Shape {
SQUARE,
CIRCLE
}
enum ColoredShape {
[`${keyof Color}_${keyof Shape}`]
}
console.log(ColoredShape.RED_SQUARE, ColoredShape.BLUE_CIRCLE)
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
- I think?
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
Inizia esaminando l’interazione proposta nell’issue tra i template literal types e le coppie chiave/valore di enum. Il payload non indica file, test o punti di ingresso, e la sintassi e la semantica rimangono speculative. Il lavoro sarebbe completato solo quando fossero definiti un design stabilito per le permutazioni di enum e un piano chiaro di implementazione e validazione.
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
- Da chiarire
- Idoneità per principianti
- 25/100