找不到名称“PropertyKey" [英] Cannot find name 'PropertyKey'

查看:35
本文介绍了找不到名称“PropertyKey"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个项目上运行 Webpack,但出现多个错误

I am trying to run Webpack on a project and I am getting multiple errors

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'.

我应该安装所有类型,所以我不确定这些是从哪里来的.我尝试从编译的项目中复制 package.json ,但没有帮助.我错过了什么?

I should have all my typings installed so I am not sure where these are coming from. I tried copying over a package.json from a project that compiles but it didn't help. What am I missing?

我的 tsconfig 看起来像这样

My tsconfig looks like this

{
  "compilerOptions": {
    "target": "es5",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

推荐答案

我在 0.9.35 使用 @types/core-js 时遇到同样类型的错误

I am getting the same kind of errors with @types/core-js at 0.9.35

可能是别的东西..

编辑

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

There has been some changes on the repo last week. You can read the issue on github and see the changes via these links:

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

https://github.com/Definitely1Typed/Definitely1Typed/Definitely1d提交/f2c5c990e448550fcebec071c25e6a1e5766dde7

我的解决方案是改变

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

"lib": ["es5", "dom"] to "lib": ["es6", "dom"] in the compilerOptions object in my tsconfig files.

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

By doing this I made the errors disappear without downgrading to 0.9.35

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

Note: You dont need to change the target (mine is still es5)

这篇关于找不到名称“PropertyKey"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆