microsoft / microsoft/TypeScript

Renaming a module with a default export should rename default imports which match the filename

Aperta
#27,193 0 commenti 11 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

Search Terms

rename default import

Suggestion

I noticed that recently it became possible to auto-import default exports of modules:

// foo.ts

export default 42;
// bar.ts

const x = 3 + foo
//               ^ control-space here will offer to `import foo from './foo'`

This is great and finally makes default exports worth using in TypeScript, so thank you!

Also recently, TypeScript got native support for refactoring names of modules. Now, what would be really awesome is if the rename refactor for modules could take into account default exports, so that when we rename foo.ts to baz.ts this would happen in bar.ts:

-import foo from './foo';
+import baz from './baz';

-const x = 3 + foo;
+const x = 3 + baz;

Basically, try to preserve the cases where the name given to a default import matches that of the module being imported. For cases where a default export is imported with a name not matching the module, it would leave it alone:

-import customName from './foo';
+import customName from './baz';

const x = 3 + customName;

This would really make default exports exceptionally useful in TypeScript, because it would potentially reduce by half the number of refactoring gestures needed to rename a set of terms which are 1-to-1 with modules.

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. new expression-level syntax)

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 nel refactoring di ridenominazione dei moduli del modulo language-service di TypeScript e segui il comportamento esistente descritto nell’issue. Aggiungi la copertura per i nomi delle importazioni predefinite corrispondenti e non corrispondenti; il lavoro è completato quando la ridenominazione di foo.ts in baz.ts aggiorna un’importazione corrispondente e il suo utilizzo, modificando solo il percorso per customName.

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

Valutazione

Stack tecnologico
typescript
Ambito
developer-experience, tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.