typescript - Aynı özelliğin setter ve getter'ı, eslint imzalarının bitişik olması gerektiği hatasını tetikliyor
İki setter ve getter tanımladığım bir sınıf (web-component) oluşturdum, biri expressionValue diğeri scoreValue için. Şimdi bu hataları alıyorum:
Tüm 'expressionValue' imzaları bitişik olmalıdır @typescript-eslint/adjacent-overload-signatures
Tüm 'scoreValue' imzaları bitişik olmalıdır @typescript-eslint/adjacent-overload-signatures
Ve merak ediyorum, bu hatayı düzeltip setter ve getter'larımı nasıl koruyabilirim. Yoksa imkansız mı, ve bunu başarmanın tek yolu mu .eslintrc.js dosyasında @typescript-eslint/adjacent-overload-signatures: 0 ayarlamak?
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 ?? '';
}
}
Cevap #1
Buradaki anahtar kelime bitişik. Yani aynı özellik için get ve seti birbirinin yanına koymanız gerekiyor:
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
}
Ben her zaman önce getter’ı, sonra setter’ı listelerim, ama ESLint’in umursadığını sanmıyorum, yeter ki mülkün iki parçası yan yana olsun.
