microsoft / microsoft/TypeScript
Refactorings to convert from function declarations to function expressions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Suggestion
🔍 Search Terms
refactoring quick fix vs code action
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
We already have refactorings to convert function expressions (arrow or non-arrow) to a function declaration, e.g. we can use "convert to named function" on both of these:
const fn1 = function () {
return 1;
};
const fn2 = () => {
return 1;
};
However, there is no refactoring to convert in the opposite direction—from a function declaration to a function expression.
I would like to suggest adding these refactorings so we cover all possibilities.
Note we do already have these refactorings (https://github.com/microsoft/TypeScript/pull/28250):
- "Convert to arrow function"
- "Convert to anonymous function"
However these only work on function expressions—they don't work on function declarations. Perhaps we could fix this by extending the scope of those refactorings so they do work on function declarations.
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
Beginnen Sie mit der Untersuchung der bestehenden Refactorings "Convert to arrow function" und "Convert to anonymous function" und konzentrieren Sie sich darauf, wie sie derzeit mit function expressions umgehen. Erweitern Sie den relevanten Refactoring-Geltungsbereich auf function declarations, und verifizieren Sie, dass declarations in die angeforderten Formen konvertiert werden können, ohne das Laufzeitverhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100