ESLint:在打字稿中未定义“部分”

时间:2019-12-21 11:57:21

标签: reactjs typescript pycharm eslint typescript-eslint

ESLint无法识别出Partial的打字稿,但是编译后的模块没有给出任何错误。

const initialState: IAuthState = {
  authenticated: false,
  processing: false,
};

const authReducer = (state: IAuthState = initialState, action: any): IAuthState => {
  const State = (newState: Partial<IAuthState>): IAuthState => ({...state, ...newState});

  switch (action.type) {
    case Actions.SIGN_IN_PROCESS_INITIATED:
      return State({processing: true});

    case Actions.SIGN_IN_PROCESS_FAILED:
      return State({processing: false});

    default:
      return state;
  }
};

我知道可以用// eslint-disable-next-line no-undef来消除此错误,但是我仍然想要对此做一个解释,并寻求一个永久性的解决方案,这样我就不会出现错误 Error 了。

1 个答案:

答案 0 :(得分:2)

前段时间,我有一个类似的案例,并通过将@typescript-eslint/parser安装为devDependency并将其包含在eslint config中来解决它:

  "extends": [..., "@typescript-eslint/parser"],