Search code examples
angulartypescripteslinteslintrctypescript-eslint

Typescript/Angular/ESlint: no-unused-vars for constructor params


I have the following code snippet on my typescript class from angular project (v13):

import { Component } from '@angular/core';
import { MyService } from 'service';

@Component({
  selector: 'app-example',
  templateUrl: './example.component.html'
})

export class ExampleComponent {
   constructor(
       private myService: MyService  
   ) {}

   getUsers() {
      this.myService.getUsers().subscribe(response => {
      // do something;
      })
  }
}

I run the project with ESlint version 7.26.0 and extended the following plugins:

"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates",
"eslint:recommended"

the lint error I got when running ng lint is:

'mySerive' is defined but never used no-unused-vars

Obviously, myService is being used on my class.

Is that an expected behaviour or how to fix this issue?

PS: I don't want to disable the rule.


Solution

  • Fixed by adding "plugin:@typescript-eslint/recommended" plugin to the ESlint config.

    Reason: https://stackoverflow.com/a/58368341/17825554