microsoft / microsoft/TypeScript
refactoring for extracting return type of a function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Dateien, Tests oder Einstiegspunkte. Beginne damit, TypeScripts bestehende Refactoring-Infrastruktur zu lokalisieren, und lege anschließend fest, wie die angeforderte Extraktion des Rückgabetyps mit den Typ- und Schnittstellenformen des Beispiels umgehen soll; als erledigt gilt die Aufgabe, wenn das Refactoring für den angegebenen Funktionsausdruck-Anwendungsfall funktioniert und seine Ausgabe durch Tests abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100