ESLint: Parsing error: Unknown compiler option 'noUncheckedIndexedAccess'

ESLint: Parsing error: Unknown compiler option 'noUncheckedIndexedAccess'

我如下更改了我的 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
  }
}

有什么办法可以解决这个问题吗?

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

因此,这是有问题的行:

"noUncheckedIndexedAccess": true,

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

安装最新版typescript解决问题

npm i typescript@latest