【问题标题】:ESLint: 'Partial' is not defined in typescriptESLint:打字稿中未定义“部分”
【发布时间】:2020-04-13 14:24:20
【问题描述】:

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 抑制,但我仍然想要对此进行解释和永久解决方案,这样我就不会得到这个错误错误

【问题讨论】:

  • 这感觉就像在 eslint 配置中没有正确设置 Typescript 解析器。你检查过吗?
  • 你能建议需要什么配置吗?

标签: reactjs typescript pycharm eslint typescript-eslint


【解决方案1】:

我前段时间遇到过类似的情况,通过将@typescript-eslint/parser 安装为 devDependency 并将其包含在 eslint 配置中来修复它:

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

【讨论】:

  • 文档说它需要在 eslint 配置中用作 parser 而不是 extends,如下所示: "parser": "@typescript-eslint/parser"
猜你喜欢
  • 2020-02-12
  • 2016-11-06
  • 2016-09-05
  • 2018-04-20
  • 1970-01-01
  • 2016-12-13
  • 2017-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多