Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect unused methods - Visual Studio Code

Is there a way to detect unused methods in a typescript file (Angular) in Visual Studio Code? I've tried a couple of plugins for Angular but in vain. Web Storm used to grey out the unused methods by default. Looking for a similar thing in VS Code.

like image 293
Santhosh Avatar asked May 02 '26 19:05

Santhosh


2 Answers

It is currently not possible to detect unused public methods in VSCode (you can check for updates here). However, if it's a private method, you can mark it as private and VSCode is able to look for whether it is used or not within the scope (although do remember: methods used in the HTML template are public).

If the public method checks are important for you, you'll have to either wait, or contribute to the VSCode community. I still use VSCode but if it is a necessity for you, just switch to WebStorm for the moment.

like image 140
Tashi Tobgay Dakpa Avatar answered May 04 '26 09:05

Tashi Tobgay Dakpa


Hi You can try to run your application with " ng serve --aot " cli command instead of " ng serve " , it shows you a whole number of these unused codes(like when you leave " ng build --prod " command).

Or you can try this method but I'm not shure of this :

https://alexjover.com/blog/tree-shaking-with-webpack-2-typescript-and-babel/

Hope it will work!

like image 37
Chris Avatar answered May 04 '26 08:05

Chris