microsoft / microsoft/TypeScript
Renaming a module with a default export should rename default imports which match the filename
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in TypeScript's language-service module rename refactor and trace the existing behavior described in the issue. Add coverage for matching and non-matching default import names; done means renaming foo.ts to baz.ts updates a matching import and its use while only changing the path for customName.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100