microsoft / microsoft/TypeScript

Refactorings to convert from function declarations to function expressions

Aperta
#44,080 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando i refactoring esistenti "Convert to arrow function" e "Convert to anonymous function", concentrandoti su come gestiscono attualmente le function expressions. Estendi l’ambito del refactoring pertinente alle function declarations e verifica che le declarations possano essere convertite nelle forme richieste senza modificare il comportamento a runtime.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.