"Delete all unused declarations" on TS imports removes code in files
See original GitHub issue- VSCode Version: 1.31.1
- OS Version: Windows 10 (not relevant)
Steps to Reproduce:
I feel that something is terribly wrong with the current behaviour of “Delete all unused declarations” codefix.
It is suggested to remove an unused import. In this context, its implicit meaning is (for me) something like "Delete all unused imports ".
But the actual behaviour can be quite dangerous, as it can remove actual code in the file body (which is definitely not something I would expect when refactoring dependencies):
We experienced this in my team recently (and deleted parts of code that should not have been deleted), and I dont understand how this can be the default behaviour.
NB: I’m not suggesting to fix the “Delete all unused declaration” codefix, rather to use another codefix when refactoring the depenency context… so I was not sure if this issue has to be posted on the Typescript repository, or here.
Does this issue occur when all extensions are disabled?: Yes
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:6 (2 by maintainers)
Top GitHub Comments
So, I’m literally staring at code changes staged for production and testing reveals nothing is saving to the database… Turns out we used ‘Delete Unused Declarations’ to clean up some code… then I googled, then I found this thread.
Seriously? I would not expect an automatic refactoring method to break my code quite so brazenly. Nor can I imagine that anyone else would expect that. I would expect an automatic refactoring to always try to be on the safe side.
That’s exactly what I would have expected.
So please change this behavior. The refactoring methods in Typescript are incredibly useful for cleaning up old javascript code (and there’s a lot of that out there), but I have to be able to rely on them to be reasonably safe.
Note that the other issue discussed here (separating the removal of all unused imports from the removal of all unused declarations) is also a very good idea, but totally independent of the issue of the removed code (and won’t fix that issue).