【问题标题】:Parsing error with eslint in typescript, lint doesnt get the parserOptions config在 typescript 中使用 eslint 解析错误,lint 没有得到 parserOptions 配置
【发布时间】:2020-10-18 02:49:52
【问题描述】:

我不知道为什么会出现这个错误

You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project"

这是我的配置

tsconfig

{
  "compilerOptions": {
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "jsx": "react",
    "rootDir": "src",
    "baseUrl": "src",
    "paths": {
      "@/*": [
        "*"
      ]
    },
    "allowJs": true,
    "resolveJsonModule": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "src/main/test/cypress"
  ]
}

.eslintrc.json

{
  "extends": "standard-with-typescript",
  "parserOptions": {
    "projects": "./tsconfig.json"
  },
  "rules": {
    "@typescript-eslint/consistent-type-definitons": "off",
    "@typescript-eslint/strict-boolean-expressions": "off"
  }
}

我也有这个 AccountModel 类

export type AccountModel = {
    accessToken: string
}

哪个 vscode 指出错误,说“解析错误:预期类型”我缺少什么?

【问题讨论】:

标签: typescript eslint


【解决方案1】:

转到您的 eslintrc.json 并尝试以下配置:

{
  "extends": [
    "standard-with-typescript",
    "plugin:@typescript-eslint/recommended"
  ],
  "parserOptions": {
    "project": "./tsconfig.json",
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "rules": {
    "import/extensions": 1,
    "import/no-named-as-default": 0,
    "@typescript-eslint/strict-boolean-expressions": 0,
    "@typescript-eslint/explicit-module-boundary-types": 0
  }
}

【讨论】:

  • 帮助我的具体线路是"project": "./tsconfig.json"
猜你喜欢
  • 2021-04-04
  • 2021-11-01
  • 2020-11-10
  • 2020-11-30
  • 2020-09-01
  • 2020-05-24
  • 2011-07-17
  • 2022-12-18
  • 1970-01-01
相关资源
最近更新 更多