代码之家  ›  专栏  ›  技术社区  ›  Krzysztof Kaczyński

同一属性的setter和getter调用eslint签名应为adjacent错误

  •  0
  • Krzysztof Kaczyński  · 技术社区  · 6 年前

    我创建了一个类(web组件),在这个类中我声明了两个setter和getter,一个用于 expressionValue 第二个 scoreValue . 现在我发现了这些错误:

    我想知道怎样才能修正这个错误来保持我的二传手和接球手。 或者这是不可能的,唯一的方法就是设置这个 @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 ?? '';
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   T.J. Crowder    6 年前

    这里的关键词是 adjacent . 所以你需要把 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
    }
    

    我总是先列出getter,然后再列出setter,但我认为ESLint不在乎,只要属性的两个部分相邻即可。