microsoft / microsoft/TypeScript
Convert named tuple into object literal type.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
refactor
Suggestion
Provide a refactor that convert named tuple into object literal type.
Use Cases
Now we have named tuple.
It's common to write a tuple to pass multiple value.
As time goes on, you may add many other fields into tuple.
You cannot take a subsequence in the middle or the end of the tuple.
If we could convert that into an object, That would be useful.
Examples
type Tuple = [number, number]
function aggregate(items: number[]): Tuple {
// ...
return [min, max]
}
const [ min, max ] = aggregate(items)
Growth to
type Tuple = [number, number, number, number, number, number]
function aggregate(items: number[]): Tuple {
// ...
return [min, max, avg, mid, first, last]
}
const [ min, max, avg, mid, first, last ] = aggregate(items)
If we want first and last only
const [ , , , , first, last ] = aggregate(items) // too many '.'
const result = aggregate(items);
const first = result[4] // magic number
const last = result[5] // magic number
If we have the refactor
// add names into tuple
type Tuple = [min: number, max: number, avg: number, mid: number, first: number, last: number]
// apply refactor
type Tuple = {min: number, max: number, avg: number, mid: number, first: number, last: number}
function aggregate(items: number[]): Tuple {
// ...
return {min, max, avg, mid, first, last}
}
const { first, last } = aggregate(items)
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.
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’infrastruttura di refactoring del TypeScript language-service e i test di refactoring esistenti, quindi confronta le relative convenzioni con gli esempi di named tuple in questa issue. Il lavoro è completato quando un refactoring può convertire un tipo named tuple in un tipo object literal equivalente e supporta l’uso basato sulle proprietà descritto, con test che coprano la trasformazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- developer-experience
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 32/100