microsoft / microsoft/TypeScript
refactoring for extracting return type of a function
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
refactoring extract return type function method interface inferred
Suggestion
A new refactoring for function expressions that extracts the return type of the function as an interface or type.
Use Cases
Imagine a complex function that combines many types of data into a complex object. Compiler can infer the return type, but writing it out by hand takes time. Type needs a name when you want to use it elsewhere in the code (for example as a parameter type for another function).
Examples
Imagine A, B, C, D are non trivial types. (e.g. objects with many properties)
before:
function fooFunc(a: A, b: B, c: C, d: D) {
return {
...a,
...b,
foo: {...c, d}
}
}
after:
type FooFuncReturn = A & B & { foo: C & D }
// or when possible an interface type with would be even better
function fooFunc(a: A, b: B, c: C, d: D): FooFuncReturn {
return {
...a,
...b,
foo: {...c, d}
}
}
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
L’issue non indica file, test o punti di ingresso. Inizia individuando l’infrastruttura di refactoring esistente di TypeScript, quindi definisci come l’estrazione richiesta del tipo restituito debba gestire le forme di tipo e interfaccia dell’esempio; il lavoro è completo quando il refactoring funziona per il caso d’uso di espressione di funzione indicato e il relativo output è coperto dai test.
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
- Abbastanza chiara
- Idoneità per principianti
- 35/100