预期的箭头参数关闭方法有毛刺问题,不使用'this'。使用函数代替

问题描述 投票:-2回答:1

这是代码段

public async personNews(serviceBranch?: string[]): Promise<INews> {
    const fetchResult: IPersonNewsFetchResultEntry[] = await this._get('api/person/news/', newsSchema, true) as IPersonNewsFetchResultEntry[];
    let serviceBranches: string[] = [];
    serviceBranches = fetchResult.filter((entry: IPersonNewsFetchResultEntry, index: number, array: IPersonNewsFetchResultEntry[]): boolean => {
      return array.findIndex(({unitID}): boolean => entry.unitID === unitID) === index;
    }).map((entry): string => entry.unitID);
    if (serviceBranch) {
      this._moveServiceBranchInArray(serviceBranches, foundIndex => foundIndex === serviceBranch?.[0], 0);
    } 

划线错误:

ERROR: 17:31  typedef                      expected arrow-parameter: '{unitID}' to have a typedef

ERROR: 18:13  typedef                      expected arrow-parameter: 'entry' to have a typedef

ERROR: 20:53  typedef                      expected arrow-call-signature to have a typedef

ERROR: 20:55  typedef                      expected arrow-parameter: 'foundIndex' to have a typedef

另一个代码段:

  private _moveServiceBranchInArray<T>(array: T[], pred: (x: T) => boolean, index: number): void {
    index = Math.max(Math.min(index, array.length - 1), 0);
    const curPos: number = array.findIndex(pred);
    if (curPos < 0) {
      return;
    }
    [array[curPos], array[index]] = [array[index], array[curPos]];
  }
ERROR: 39:11  prefer-function-over-method  Class method does not use 'this'. Use a function instead.

我已经修复了大多数,但是这些拒绝消失。

typescript eslint typescript-typings lint
1个回答
0
投票

回答标题中的问题,得到的原因

© www.soinside.com 2019 - 2024. All rights reserved.