Back to Angular

Unused Standalone Imports

adev/src/content/reference/extended-diagnostics/NG8113.md

22.0.0-next.10887 B
Original Source

Unused Standalone Imports

This diagnostic detects cases where the imports array of a @Component contains symbols that aren't used within the template.

typescript
@Component({
  imports: [UsedDirective, UnusedPipe],
})
class AwesomeCheckbox {}

What's wrong with that?

The unused imports add unnecessary noise to your code and can increase your compilation time.

What should I do instead?

Delete the unused import.

typescript
@Component({
  imports: [UsedDirective],
})
class AwesomeCheckbox {}

What if I can't avoid this?

This diagnostic can be disabled by editing the project's tsconfig.json file:

json
{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "unusedStandaloneImports": "suppress"
      }
    }
  }
}

See extended diagnostic configuration for more info.