typescript - 在 typescript 中使用 eslint 解析错误,lint 没有得到 parserOptions 配置

标签 typescript eslint

我不知道为什么我会收到这个错误

You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project"
这是我的配置
配置文件
{
  "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 指出一个错误,说“解析错误:类型预期”我缺少什么?

最佳答案

转到您的 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
  }
}

关于typescript - 在 typescript 中使用 eslint 解析错误,lint 没有得到 parserOptions 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62612742/

相关文章:

eslint - 是否有 ESLint 规则在分配上对齐 `=`

angular - 在 Angular Directive(指令)组件之外调用函数

typescript - angular2 - 路径改变时终止可观察间隔的最佳方式

typescript - TypeScript 中带有区分联合的类型安全强制转换(如 C++ 的dynamic_cast)

javascript - 如何在 vim 中添加 react jsx 作为 javascript 文件类型并启用 eslinting、自动完成?

reactjs - axios.delete(url[,config]) : Type has no properties in common with type 'AxiosRequestConfig'

javascript - 如何在修复文件时连续自动运行 gulp eslint -- 如何设置 watch

node.js - 开 Jest , typescript ,ts-jest : Coverage is slightly incorrect

typescript - 拆分 appcomponent 后,Angular 2 Tour of Heroes 项目无法正常工作

angular - 将angular 9升级到10后如何更新eslint的配置