【问题标题】:ESLint: Parsing error: Unknown compiler option 'noUncheckedIndexedAccess'ESLint:解析错误:未知的编译器选项“noUncheckedIndexedAccess”
【发布时间】:2021-03-20 13:51:49
【问题描述】:

我将节点项目的tsconfig.json 文件的配置更改如下,现在它给出了ESLint: Parsing error: Unknown compiler option 'noUncheckedIndexedAccess' 错误。

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
      "outDir": "lib",
      "sourceMap": true,
      "declaration": false,
      "moduleResolution": "node",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "target": "es2018",
      "typeRoots": [
          "node_modules/@types"
      ],
      "skipLibCheck": true,
      "lib": [
          "es2017",
          "dom"
      ],
      "module": "CommonJS",
      "baseUrl": "./",
      "noUnusedLocals": true,
      "noUnusedParameters": true,
      "noUncheckedIndexedAccess": true,
      "strictNullChecks": true
  }
}

有没有办法解决这个问题?

【问题讨论】:

  • typescript 和 eslint 有哪些版本?
  • eslint 版本是 7.6.0,typescript 版本是 3.8.0
  • `noUncheckedIndexedAccess` 可从 typescript 4.1 获得
  • 更新打字稿后错误现在消失了,感谢@HTN

标签: node.js typescript eslint tsconfig


【解决方案1】:

正如 HTN 在他的评论中指出的那样,noUncheckedIndexedAccess 从 4.1 开始可用。 docs 确认这一点。

因此,这是有问题的行:

"noUncheckedIndexedAccess": true,

您的 Typescript 3.8.0 比它尝试使用的功能旧,因此出现错误。您可以使用当前的 Typescript,但删除该行,或者您可以将 Typescript 升级到至少 4.1 版本。这两种方法都可以解决问题,但 Typescript 版本升级通常被认为是一种更好的方法,因为它会为您提供新选项,而不必限制对功能的访问。

【讨论】:

    【解决方案2】:

    安装最新版本的typescript即可解决问题

    npm i typescript@latest
    

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 2018-07-25
      • 2019-02-19
      • 1970-01-01
      • 2021-12-29
      • 2018-05-27
      • 2021-07-14
      • 2019-10-07
      • 1970-01-01
      相关资源
      最近更新 更多