MongDB cannot find type definition for Promise

I created a new project, installed several type definitions (from DefinitelyTyped) and made a base src/go.tsfile.

Whenever I port the code, I get a ton of errors TS2304: Cannot find name 'Promise'!
./typings/mongodb/index.d.tsrefers to Promise, but the compiler does not seem to find this.
Please note: I also installed dt~promise.

Screenshot (Errors on the left side, installed type definitions and application code are on the right)

Content 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?

+4
source share
3 answers

( , @types ) , CoreJS.

, , .

:

  • , MongoDB "Promise".
  • CoreJS. , NPM, Typings. , - Typings, - :
    • typings install dt~core-js --save --global
  • 😁

, .

+5

, mongodb mongoose.

mongodb , ES6, , target typescript tsconfig.json es6, :

tsconfig.json:

{
    "compilerOptions": {
        ...
        "target": "ES6",
        ...
    }
}
+1

For types typings install core-js --ambient --save. This works for me.

0
source

Source: https://habr.com/ru/post/1651133/


All Articles