Back to Angular

Clean up unused imports

adev/src/content/reference/migrations/cleanup-unused-imports.md

22.0.0-next.10688 B
Original Source

Clean up unused imports

As of version 19, Angular reports when a component's imports array contains symbols that aren't used in its template.

Running this schematic will clean up all unused imports within the project.

Run the schematic using the following command:

shell
ng generate @angular/core:cleanup-unused-imports

Before

angular-ts
import {Component} from '@angular/core';
import {UnusedDirective} from './unused';

@Component({
  template: 'Hello',
  imports: [UnusedDirective],
})
export class MyComp {}

After

angular-ts
import {Component} from '@angular/core';

@Component({
  template: 'Hello',
  imports: [],
})
export class MyComp {}