繁体   English   中英

typescript 中的 eslint 解析错误,lint 没有得到 parserOptions 配置

[英]Parsing error with eslint in typescript, lint doesnt get the parserOptions config

我不确定为什么会收到此错误

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 class

export type AccountModel = {
    accessToken: string
}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM