我创建了一个类(网络组件),在其中声明了两个 setter 和 getter,一个expressionValue用于scoreValue. 现在我收到了这些错误:
所有 'expressionValue' 签名都应该与 @typescript-eslint/adjacent-overload-signatures 相邻
所有 'scoreValue' 签名应该相邻 @typescript-eslint/adjacent-overload-signatures
我想知道如何修复此错误以保留我的 setter 和 getter。或者这是不可能的,只有一种方法是@typescript-eslint/adjacent-overload-signatures: 0在.eslintrc.js文件中设置它?
class BinaryExpressionItem extends KKWebComponent implements KKBinaryExpressionItem {
public static TAG: string = `${CONSTANTS.TAG_PREFIX}-binary-expression-tem`;
private readonly expression: HTMLElement = <HTMLElement>this.shadowRoot.querySelector('var');
private readonly score: HTMLElement = <HTMLElement>this.shadowRoot.querySelector('mark');
constructor() {
super(template);
}
set expressionValue(value: string) {
this.expression.textContent = value;
}
set scoreValue(value: string) {
this.score.textContent = value;
}
get expressionValue(): string {
return this.expression.textContent ?? '';
}
get scoreValue(): string {
return this.score.textContent ?? '';
}
}
Run Code Online (Sandbox Code Playgroud)
T.J*_*der 12
这里的关键词是相邻。因此,您需要将同一属性的get和放在set一起:
class BinaryExpressionItem extends KKWebComponent implements KKBinaryExpressionItem {
public static TAG: string = `${CONSTANTS.TAG_PREFIX}-binary-expression-tem`;
private readonly expression: HTMLElement = <HTMLElement>this.shadowRoot.querySelector('var');
private readonly score: HTMLElement = <HTMLElement>this.shadowRoot.querySelector('mark');
constructor() {
super(template);
}
get expressionValue(): string { // The ones for expressionValue
return this.expression.textContent ?? ''; // The ones for expressionValue
} // The ones for expressionValue
// The ones for expressionValue
set expressionValue(value: string) { // The ones for expressionValue
this.expression.textContent = value; // The ones for expressionValue
} // The ones for expressionValue
get scoreValue(): string { // The ones for scoreValue
return this.score.textContent ?? ''; // The ones for scoreValue
} // The ones for scoreValue
// The ones for scoreValue
set scoreValue(value: string) { // The ones for scoreValue
this.score.textContent = value; // The ones for scoreValue
} // The ones for scoreValue
}
Run Code Online (Sandbox Code Playgroud)
我总是先列出 getter,然后是 setter,但我认为 ESLint 并不关心,只要属性的两个部分彼此相邻即可。
| 归档时间: |
|
| 查看次数: |
2212 次 |
| 最近记录: |