首页 > 解决方案 > 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但我仍然想要一个解释和一个永久的解决方案,这样我就不会得到这个不是那么错误的错误

标签: reactjstypescriptpycharmeslinttypescript-eslint

解决方案


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

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

推荐阅读