DEV Community

Cover image for Finding dead code in the typescript project
Alexey Lysenko
Alexey Lysenko

Posted on

Finding dead code in the typescript project

For finding "dead" code in a typescript project, I use package:
yarn add -D ts-prune

after installation, add a script to package.json file:



{
...
  "scripts": {
    "find-deadcode": "ts-prune"
  }
}


Enter fullscreen mode Exit fullscreen mode

now use yarn find-deadcode it will find and shows all unused exports in a project

Image description

The script above will detect unused exports, even if they are used internally within the module. So you can remove export to make this code local only, or you can modify script to ignore this behavior:



{
...
  "scripts": {
    "find-deadcode": "ts-prune | grep -v '(used in module)'"
  }
}


Enter fullscreen mode Exit fullscreen mode

Top comments (0)