A simple and configurable tool for finding unused exports in TypeScript projects.
The tool wraps ts-prune and filters its output using configurable pattern-matching rules.
You can specify which files and exports to ignore. See .ts-prune.json for a starter configuration.
- Install
ts-pruneandts-nodeas dev dependencies in your project:
npm install --save-dev ts-prune ts-node
# or
pnpm add -D ts-prune ts-node
# or
yarn add -D ts-prune ts-node-
Copy
check-unused.tsto your project, e.g. toscripts/check-unused.ts. -
Copy
.ts-prune.jsonto your project's root and adapt it to your needs. -
Add a script to your
package.json:
{
"scripts": {
"check-unused": "ts-node scripts/check-unused.ts"
}
}When true, exports marked as "used in module" by ts-prune are ignored.
An array of filtering rules. Each rule has:
files: Array of regex patterns to match file paths.exports: Array of regex patterns to match export names.
If a file matches a rule's file patterns and the export matches that rule's export patterns, the export is ignored.
For example, the following rule will ignore config and middleware exports in middleware.ts:
{
"files": ["middleware.ts"],
"exports": ["config", "middleware"]
}See .ts-prune.json for a starter configuration.
npm run check-unused
# or
pnpm check-unused
# or
yarn check-unused- 0: No unused exports found.
- 1: Unused exports detected.
✓ No unused exports found!
or
Found 5 potentially unused export(s):
src/utils/helper.ts:42 - unusedFunction
src/components/Old.tsx:10 - default
lib/legacy.ts:15 - deprecatedExport
lib/legacy.ts:23 - oldHelper
config/unused.ts:8 - UNUSED_CONSTANT
Found a bug or have an idea?
- Open an issue.
- Fork the repo, make a change on a new branch, and open a pull request.
Built on top of ts-prune by Nadeesha Cabral.