找不到名字'PropertyKey'

Jac*_*kie 19 webpack angular

我正在尝试在项目上运行Webpack,我遇到了多个错误

node_modules/@types/core-js/index.d.ts
error TS2304: Cannot find name 'PropertyKey'.
...
node_modules/@types/core-js/index.d.ts
error TS2339: Property 'for' does not exist on type 'SymbolConstructor'.
Run Code Online (Sandbox Code Playgroud)

我应该安装所有的打字机,所以我不确定它们来自哪里.我尝试从一个编译的项目复制一个package.json,但它没有帮助.我错过了什么?

我的tsconfig看起来像这样

{
  "compilerOptions": {
    "target": "es5",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

Kem*_*aya 38

@type/core-js在0.9.35时遇到同样的错误

可能是别的..

编辑

上周回购有一些变化.您可以在github上阅读该问题,并通过以下链接查看更改:

https://github.com/DefinitelyTyped/DefinitelyTyped/issues/15104

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15108/commits/f2c5c990e448550fcebec071c25e6a1e5766dde7

我的解决方案是改变

"lib": ["es5", "dom"]到我的tsconfig文件"lib": ["es6", "dom"]中的compilerOptions对象.

通过这样做,我使错误消失而不降级到0.9.35

注意:你不需要改变目标(我的仍然是es5)

  • 改为ES6不会破坏IE 11的运行吗?换句话说,ES6和浏览器合规性的后果是什么? (2认同)
  • 只要目标仍然是es5,您的代码应该能够在IE中运行. (2认同)

Jac*_*kie 7

对我来说答案是......

"compilerOptions": {
  ...
  "lib": [
    "es2016",
    "dom"
  ]
},
Run Code Online (Sandbox Code Playgroud)


Saa*_*iel 5

降级@types/core-js至0.9.35.

升级到0.9.37后,我遇到了同样的问题.