[英]MongDB cannot find Promise type definition
I have created a new project, installed few type definitions (from DefinitelyTyped) and made a basic src/go.ts
file. 我创建了一个新项目,安装了几个类型定义(来自DefinitelyTyped)并创建了一个基本的
src/go.ts
文件。
Whenever I transpile the code, I get a ton of TS2304: Cannot find name 'Promise'
errors! 每当我转换代码时,我得到了大量的
TS2304: Cannot find name 'Promise'
错误!
The ./typings/mongodb/index.d.ts
is referencing the Promise
, but the compiler does not seem to find that. ./typings/mongodb/index.d.ts
引用了Promise
,但编译器似乎没有找到它。
Please note that I have dt~promise
installed as well. 请注意,我已经
dt~promise
安装好了。
Screenshot (Errors on the left side, type definitions installed and the app code are on the right) 屏幕截图 (左侧错误,已安装类型定义,应用程序代码位于右侧)
Content of typings.json
: 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"
}
}
Any thoughts? 有什么想法吗?
I've experienced the same issue (more or less, using @types instead of typings) and was able to solve it by installing the type definitions for CoreJS . 我遇到了同样的问题(或多或少,使用@types而不是typings)并且能够通过安装CoreJS的类型定义来解决它。
Apologize for linking to a library, this is my first post so I am unable to provide more than two links per post. 为链接到图书馆道歉,这是我的第一篇文章,因此我无法为每个帖子提供两个以上的链接。
typings install dt~core-js --save --global
I hope this resolves your issue. 我希望这能解决你的问题。
I had the same issue installing lastest version of mongodb and mongoose typings. 我有同样的问题安装最新版本的mongodb和猫鼬类型。
The new definition file for mongodb assumes you are using ES6 promise so if you change the target
of the typescript compiler in the tsconfig.json
to es6
it should do the trick : mongodb的新定义文件假设您正在使用ES6承诺,因此如果您将
tsconfig.json
中的tsconfig.json
编译器的target
更改为es6
它应该可以解决这个问题:
tsconfig.json: tsconfig.json:
{
"compilerOptions": {
...
"target": "ES6",
...
}
}
For typings: typings install core-js --ambient --save
. 对于打字:
typings install core-js --ambient --save
。 It works for me. 这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.