Reputation: 341
There are tslint rules available for private method. But How can I find out if the public method is not used anywhere in the project and hence candidate for the dead code. I am using Visual studio code for Typescript.
Upvotes: 17
Views: 17406
Reputation: 1324
It's a quite complex issue with VSCode for now. Suggest you switch to WebStorm https://dev.to/mokkapps/why-i-switched-from-visual-studio-code-to-jetbrains-webstorm-939
There is a lot of complaint about it on this thread https://github.com/microsoft/TypeScript/issues/29293 but unfortunately it never gets resolved.
Upvotes: 3
Reputation: 81
I had the same problem, and dpdm was the best found solution. But I wanted one integrated in Visual Code so in the end was created an extension named Find unused exports. It allows to easily see and go to unused exports in a js/ts project.
Upvotes: 3
Reputation: 414
Have a look to https://www.npmjs.com/package/ts-unused-exports
It produces an output like this
$ ts-unused-exports tsconfig.json
4 modules with unused exports
src/lambda: handler
src/routes/crud: default
Upvotes: 9
Reputation: 18322
Well, I don't think you can do that for all your code, but you can open the context menu over a method/function/property, and then select 'find all references'. If none is found, you can mark it as a candidate for deletion.
Of course this method is not perfect. For example, you could call a method from an object which is an instance of a class but has been cast to any
previously, but it's a starting point.
Upvotes: 0