TypeScript: Rename a symbol of a named export: Do not create export alias
- VSCode Version: 1.30
- OS Version: Win 10
When I rename a symbol which is a named export in a module, then there is just an alias created in the module export (VS Code 1.30). What I would expect is that the symbol is renamed in the module export AND all in all modules that are importing it (that is the bevavior of 1.29.1). Or an option by which I can specify the old behavior. This feature is soo useful to rename a bunch of modules.
Release notes of 1.30 only include some rename changes for destructuring , but I did not have any destructuring in code.
Old (1.29.1):

New (1.30):

Does this issue occur when all extensions are disabled?: Yes, running clean versions of 1.30, 1.29.1
PS: Typescript 3.2.2 in both tests.
// EDIT:
Actually, after all VS Code 1.29.1 did use Typescript 3.1.4 in the first test, not 3.2.2. Switching to TS 3.2.2 with the old 1.29.1 version, the same behavior (just aliasing the export instead of renaming in the whole workspace) reoccurs. I am not sure, if there are interdependencies between VS Code and TS and therefore leave the issue open or not?
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 31
- Comments: 20 (3 by maintainers)
unckeck the following preferences in settings to make it work:
typescript.preferences.useAliasesForRenamesI’ll second this: a global option for the old behaviour feels necessary. This new
aliasdoes not work at all with the way some people work and imposing this new “feature” on people for something as common as symbol rename is not nice.I’m sorry but for me the “improved” version is actually felt like a bug that is now preventing me from using renaming all together: I don’t want my codebase to be littered with aliases.
Just let us rename stuff please. Even a rollback of the feature altogether would be better, with an option to opt-in for alias renaming when things are properly figured out.
Does the setting
typescript.preferences.useAliasesForRenamesin vscode solve the problem?This behaviour is terrible.
Honestly, this new
exportalias behavior is cumbersome for refactorings. If you have something likeexport {Y}and you rename it toY2, the result isIn order to get all symbols in the module to be also named
Y2, I have to manually deleteYin theexportand then fix allYlines in the module. I also have to pay attention, that I rename the symbolYin the export statement itself (not somewhere else in the module). Otherwise, there is just an alias created in the export and the rest of the workspace that importsYdoes not get the new name.Before, I could just grab any reference of
Ysymbol, pressF2and it gets renamed in all places (module+workspace).All in all, I also would really appreciate to have the old behavior back
While we didn’t explicitly mention
exports, symbolically they behave very similarly to destructuring and I don’t see why we wouldn’t have made them behave the same way.However, I can understand wanting a rename mode that works the old way, too - so i’ll make this as a suggestion.
It would be great if we can have both renaming behaviors at the same time, rather than disabling some behavior once for all.
9 times out of 10 I would prefer it to work like the old way.
For example, using destructuring (not imports):
When I
Rename Symbolonhelloin the function I want it to renamehelloininitialStatetoo. And vice versa.I usually do not get naming right the first time around. Often I’ll just go w/
xto not get hung up on naming until I get something working, and maybe rename things a few times before I’m done. The old behavior of rename symbol was great for this.I’m 😢this behavior was changed without providing an option to maintain the old behavior.
It’s 2020 now, any further progress?
I tried to refactor a prop from a parent React Component with a child SFC, and got the following (crazy) behaviour:
Before rename
After rename
It correctly renamed the interface, then aliased the props for actual usage in the ChildComponent(!) This cannot be the desired behaviour…
Apparently for someone, somewhere, this is how it is supposed to work!