跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

Unused Standalone Imports ​

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

ts
@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.

ts
@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.

基于 MIT 许可证发布。