Skip to main content

Unused exports

unusedExportsDetection finds exports that are never imported from any reachable entry point.

Use it after entry points are trustworthy. Incomplete entry points make live exports look unused.

Autofix is available for straightforward cases.

What this check does

unusedExportsDetection analyzes the dependency graph starting from the defined entry/root entry points. It identifies any exported members (functions, classes, variables, etc.) that are not reachable via any import or require statement from the project's entry points.

This allows you to identify dead code that can be safely removed to improve maintainability and reduce bundle size.

Why it is important

  • Reduces Dead Code: Automatically identifies code that can be safely removed, keeping the codebase clean.
  • Improves Bundle Size: Removing unused exports helps keep production bundles small and efficient.
  • Improves Maintainability: Easier to navigate and understand the codebase when dead exports are eliminated.

Monorepo Note

When working in a monorepo, detecting unused exports might work best at the workspace root. This allows the detector to have context of all packages and check whether a dimension of a given export is used across the entire monorepo, not just within a single workspace.

Configuration

Below is an example of how unusedExportsDetection fits within the rules array. It demonstrates defining general production and development entry points at the rule level.

It showcases the possibility of then overriding them with specific validEntryPoints at the check level when necessary.

{
"rules": [
{
"path": ".",
"prodEntryPoints": ["src/main.ts"],
"devEntryPoints": ["**/*.test.ts"],
"unusedExportsDetection": {
"enabled": true,
"autofix": true,
// overrides the rule-level entry points settings for this check
"validEntryPoints": ["src/specific-entry.ts"],
"ignoreFiles": ["**/legacy.ts"],
"ignoreExports": ["legacyExport"],
"ignoreTypeExports": true,
"ignore": {
"**/types.ts": ["Foo*", "Bar*"]
}
}
}
]
}

Options

  • enabled: Enables the unused exports check.
  • validEntryPoints: Files whose exports should be treated as valid public API roots and never reported as unused.
  • ignoreTypeExports: Skip export type and interface-style exports.
  • ignoreFiles: Ignore all unused-export findings for matching files.
  • ignoreExports: Ignore selected export names or globs globally.
  • ignore: Ignore specific export names for matching file globs (e.g., {"**/types.ts": "Foo*"}).
  • graphExclude: Exclude files from the dependency graph used by this detector.
  • autofix: Enables automatic removal of the export keyword for unused exports.

Also referred as

Unused Exports is also known as:

  • Dead exports
  • Unused exports detection
  • Unused code detection
  • Unused module exports
  • typescript find unused exports
  • tslint unused exports
  • eslint unused exports
  • no unused exports
  • tslint find unused exports