错误 TS2304:找不到名称 'WebAssembly'

error TS2304: Cannot find name 'WebAssembly'

我可能遇到了 TypeScript 配置问题,但我这辈子都弄不明白。我 运行 在 nodejs v11 中使用 TypeScript v3.4.5。

我只是想用打字稿编译以下代码:

const { Module, Instance } = WebAssembly;

产生错误:

error TS2304: Cannot find name 'WebAssembly'.

奇怪的是,如果我将鼠标悬停在 VSCode 中的所有 3 种类型上,它会正确解析类型并且没有显示任何错误。

如果我使用此解决方法,它会成功编译并运行:

const { Module, Instance } = (global as any).WebAssembly;

我要怎么做才能让 TS 正确识别 WebAssembly?

这是我当前的 tsconfig.json 文件:

{
    "compilerOptions": {
      "inlineSourceMap": true,
      "noUnusedLocals": true,
      "outDir": "build",
      "target":"es2018",
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "esModuleInterop": true,
      "module": "commonjs",
      "moduleResolution": "node",
      "noUnusedParameters": false

    },
    "exclude": ["node_modules"],
    "include": ["src/**/*.ts"]
  }

编辑: 它适用于此配置:

{
  "compilerOptions": {
    "removeComments": true,
    "sourceMap": true,
    "target": "es6",
    "module":"commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "lib": ["es2018", "dom"],
    "outDir": "build",
    "sourceRoot": "src",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "include": ["**/*.ts"],
  "exclude": ["**/node_modules"]
}

发生这种情况是因为根据 this comment.

,webassembly 的类型声明只能从 >3.4 的打字稿中获得

解决方案是将 typescript 至少提高到 3.6(?)