Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: refactor to "renamed" named import #28367

Closed
4 tasks done
OliverJAsh opened this issue Nov 6, 2018 · 5 comments
Closed
4 tasks done

Suggestion: refactor to "renamed" named import #28367

OliverJAsh opened this issue Nov 6, 2018 · 5 comments
Labels
Domain: Refactorings e.g. extract to constant or function, rename symbol In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@OliverJAsh
Copy link
Contributor

Search Terms

Suggestion

import { foo } from 'bob';

foo();

I want to rename the named import but only within this module.

This is possible via "renamed named imports".

A refactoring could update the import along with any internal references:

import { foo as mySpecialFoo } from 'bob';

mySpecialFoo();

I'm happy to help implementing this if other people are interested and someone can guide me. 😄

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)
@weswigham weswigham added Suggestion An idea for TypeScript In Discussion Not yet reached consensus Domain: Quick Fixes Editor-provided fixes, often called code actions. Domain: Refactorings e.g. extract to constant or function, rename symbol and removed Domain: Quick Fixes Editor-provided fixes, often called code actions. labels Nov 6, 2018
@lemoinem
Copy link

lemoinem commented Nov 7, 2018

Just a small addition: Currently, trying to rename an imported symbol renames its source (at least in VS Code).
Which might be what we want, but more often than not, isn't... And definitely isn't if the source is in (say) node_modules...
This bit me more than once... It's a major pain to undo this kind of damage...

@purpledrgn
Copy link

This seems to have already been put into effect for some time. On Version: 1.30.2 and this is how F2 / "Symbol Rename" works.

I believe it to be a total nuisance! It completely removes the ability to intentionally rename a symbol globally. I don't see any configuration option to switch it back or alternative shortcut.

I understand some people find it convenient for it to always alias, but that's single Ctrl+H or a simple "as [something]" in a single file. On the other hand if I am actively working on a feature and need to modify names of things (because it's something actively worked on; or maybe there's very good reason to rename globally) there's now no easy/safe way to do it outside of going into every file and every little symbol reference (which could be 100).

The use case it removes is far more sensitive and hard to do then the mild convenience it provides.

Please revert this change or just add back the old functionality.

cc @weswigham

@OliverJAsh
Copy link
Contributor Author

Sounds like a bug, separate from this suggestion to add this functionality as an optional refactor. @purpledrgn Perhaps open a separate issue or search to see if someone already has?

@purpledrgn
Copy link

But report #29238 (for anyone stumbling on to this problem)

@OliverJAsh
Copy link
Contributor Author

This can be closed because this is now the default behaviour. It can be disabled with these settings:

"typescript.preferences.renameShorthandProperties": false,
"javascript.preferences.renameShorthandProperties": false,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Refactorings e.g. extract to constant or function, rename symbol In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants