microsoft / microsoft/TypeScript
Suggestion: extract to function expression
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Search Terms
function expression declaration extract method refactoring code fixes
Suggestion
"Extract to function" is very useful, but it only supports generating function declarations. Some people (such as me) prefer to use function expressions instead of declarations.
For example:
const fn = () => {
const foo = 1;
const bar = foo + 2
}
If I select line 3 and extract to function, I get
const fn = () => {
const foo = 1;
const bar = newFunction(foo)
}
function newFunction(foo: number) {
return foo + 2;
}
I want:
const newFunction = (foo: number) => foo + 2;
const fn = () => {
const foo = 1;
const bar = newFunction(foo)
}
Some ideas:
- An option to toggle between expressions/declarations
- Separate refactorings for both expressions and declarations
Use Cases
Examples
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
Nell’issue non sono indicati file o test; inizia individuando il punto di ingresso esistente del refactoring “Extract to function” e i relativi test. Confronta l’output richiesto di un’espressione di funzione con il comportamento attuale delle dichiarazioni, quindi determina se il criterio di completamento previsto sia un interruttore o un refactoring separato, coprendo sia i casi TypeScript sia quelli JavaScript.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- tooling
- 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