Eslint - 解析错误:提供的库值无效:es2022

Rob*_*ste 5 typescript eslint angular typescript-eslint typescript-eslintparser

我想使用Array.prototype.at()es2022,但打字稿告诉我,如果我想使用它,我应该将 tsconfig 的 lib 属性设置为 es2022。我这样做了,它有效并且可以编译。

然而,现在 eslint 在每个 TS 文件的顶部给我一个错误。

解析错误:提供的库值无效:es2022eslint

令人惊讶的是,我在网上发现有关该错误的信息很少。我到处都看到类似的问题但这对我没有帮助。

这是我的 tsconfig:

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "strictNullChecks": false,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "sourceMap": true,
        "declaration": false,
        "downlevelIteration": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "importHelpers": true,
        "target": "es2020",
        "module": "es2020",
        "lib": ["es2022", "dom"],
        "paths": {
            "@app/*": ["src/app/*"],
            "@env/*": ["src/environments/*"]
        }
    },
    "angularCompilerOptions": {
        "enableI18nLegacyMessageIdFormat": false,
        "strictInjectionParameters": true,
        "strictInputAccessModifiers": true,
        "strictTemplates": true
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 .eslintrc.json 的相关部分:

"parserOptions": {
    "project": ["tsconfig.json", "e2e/tsconfig.json"],
    "createDefaultProgram": true,
    "ecmaVersion": "latest"
},
Run Code Online (Sandbox Code Playgroud)

我尝试设置ecmaVersion为 2021 年、2022 年和最新版本,但该错误不断弹出。

有没有办法告诉 eslint 忽略该错误?或禁用该检查?该项目编译良好。

小智 4

检查您的 @typescript-eslint/eslint-plugin 版本。如果您的打字稿版本比 @typescript-eslint/eslint-plugin 更新,则会显示该错误。