5

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

4

2 回答 2

5

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

  "extends": [..., "@typescript-eslint/parser"],
于 2020-04-20T19:49:20.337 回答
0

与其他配置参数compilerOptions一一试验后,我发现对我来说问题是我没有esnextcompilerOptions.lib.

{
  "compilerOptions": {
    // other config
    "lib": [
      "dom",
      "dom.iterable",
      "esnext" // I added this to ensure `Partial`, `Record`, and others were recognized as defined by ESLint
    ]
    // other config
  }
}
于 2022-01-25T17:03:28.597 回答