我创建了一个新项目,安装了几个类型定义(来自绝对类型)并制作了一个基本的 src/go.ts
文件。
每当我转译代码时,我都会收到大量 TS2304: Cannot find name 'Promise'
错误!./typings/mongodb/index.d.ts
引用了 Promise
,但编译器似乎没有找到。
请注意,我也安装了 dt~promise
。
Screenshot(左侧的错误,安装的类型定义和应用程序代码在右侧)typings.json
的内容:
{
"globalDependencies": {
"dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
"express": "registry:dt/express#4.0.0+20160708185218",
"express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160805091045",
"mime": "registry:dt/mime#0.0.0+20160316155526",
"mongodb": "registry:dt/mongodb#2.1.0+20160602142941",
"mongoose": "registry:dt/mongoose#4.5.4+20160807120805",
"mongoose-promise": "registry:dt/mongoose-promise#4.5.4+20160720003345",
"node": "registry:dt/node#6.0.0+20160807145350",
"promise": "registry:dt/promise#7.1.1+20160602154553",
"serve-static": "registry:dt/serve-static#0.0.0+20160606155157"
}
}
有什么想法吗?
最佳答案
我遇到了同样的问题(或多或少,使用 @types 而不是打字)并且能够通过安装 CoreJS 的类型定义来解决它。
Screenshots
为链接到图书馆而道歉,这是我的第一篇文章,所以我无法在每篇文章中提供两个以上的链接。
图片说明:
typings install dt~core-js --save --global
我希望这能解决您的问题。
关于node.js - MongoDB 找不到 Promise 类型定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38927463/