【发布时间】:2022-02-24 23:15:34
【问题描述】:
我在 Angular 项目 (v13) 的 typescript 类上有以下代码 sn-p:
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;
})
}
}
我使用 ESlint 版本 7.26.0 运行项目并扩展了以下插件:
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates",
"eslint:recommended"
我在运行 ng lint 时遇到的 lint 错误是:
'mySerive' is defined but never used no-unused-vars
显然,我的班级正在使用 myService。
这是预期行为还是如何解决此问题?
PS:我不想禁用规则。
【问题讨论】:
-
你没有收到
Constructor implementation is missing.吗?只是复制粘贴代码时的错字吗? -
是的,这是复制粘贴代码时的拼写错误。对不起!现已修复
-
抱怨是因为您在构造函数中定义了参数但从不使用它。您应该“使用”它或禁用该规则。
-
@youdateme OP 正在使用它,看看
getUsers()方法 -
不在 constructor 中,这就是它抱怨的原因... 示例:
constructor(unused) { }
标签: angular typescript eslint eslintrc typescript-eslint