简体   繁体   English

检测未使用的方法 - Visual Studio Code

[英]Detect unused methods - Visual Studio Code

Is there a way to detect unused methods in a typescript file (Angular) in Visual Studio Code?有没有办法在 Visual Studio Code 的 typescript 文件(Angular)中检测未使用的方法? I've tried a couple of plugins for Angular but in vain.我已经为 Angular 尝试了几个插件,但没有成功。 Web Storm used to grey out the unused methods by default. Web Storm 用于默认将未使用的方法灰显。 Looking for a similar thing in VS Code.在 VS Code 中寻找类似的东西。

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).嗨,您可以尝试使用" ng serve --aot " cli 命令而不是" ng serve "来运行您的应用程序,它会向您显示所有这些未使用的代码(例如当您离开" ng build --prod "命令时)。

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/ https://alexjover.com/blog/tree-shaking-with-webpack-2-typescript-and-babel/

Hope it will work!希望它会奏效!

It is currently not possible to detect unused public methods in VSCode (you can check for updates here ).目前无法在 VSCode 中检测未使用的公共方法(您可以在此处检查更新)。 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).但是,如果它是私有方法,您可以将其标记为私有,并且 VSCode 能够查找它是否在 scope 中使用(尽管请记住:在 HTML 模板中使用的方法是公共的)。

If the public method checks are important for you, you'll have to either wait, or contribute to the VSCode community.如果公共方法检查对您很重要,您将不得不等待,或者为 VSCode 社区做出贡献。 I still use VSCode but if it is a necessity for you, just switch to WebStorm for the moment.我仍然使用 VSCode,但如果您需要,请暂时切换到 WebStorm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM