使用打字稿中的eslint解析错误,lint无法获取parserOptions配置

时间:2020-06-27 16:37:37

标签: typescript eslint

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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
        
public class Destruction : MonoBehaviour
{
    public Transform[] Transforms = new Transform[5];

    public GameObject PrayingMan;

    public Losing losing;

    private void OnCollisionEnter2D(Collision2D other) 
    {
        Losing.min = Losing.fallSpd; 
        (double) Losing.max = Losing.min + 0.3; // i get all the errors on this line!
        print("min: " + Losing.min + "max: " + Losing.max + "speed: " + Losing.fallSpd);
        PrayingMan.GetComponent<Losing>().ChangeSpd();
    }
}

这是我的配置

tsconfig

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

.eslintrc.json

{
  "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"
  ]
}

我也有这个AccountModel类

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

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

1 个答案:

答案 0 :(得分:0)

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