Typescript: TS2304: Cannot find name 'Promise'

Created on 19 Sep 2016  ·  5Comments  ·  Source: microsoft/TypeScript

Using typescript 2.0.0

Question

Most helpful comment

for future searches.

the default library that the compiler injects in a compilation is one for ES5 runtimes. Promise was added in ES6/ES2015 . So:

  • If you know your engine has support of ES6 promises, e.g. node v4+, use --lib es6 (or --lib dom,es6 for websites).
  • if you are including a shim for promise, e.g. core-js, es6-shims, etc.. then npm install @types/core-js or npm install @types/es6-shim
  • if you are using a different library for your promise, e.g. bluebird, then you should not be using the global Promise directly.

All 5 comments

You really need to provide more than this. This is not a support forum, it is for tracking issues and defects with TypeScript. Maybe even the command line you are using to compile the project? You really expect people to read your mind?

@vnxyz try npm install @types/es6-shim

@whitecolor that might get it to compile in certain situations, but that may not solve the problem. We need more information to know what is going on. It could be the OP assumes they are targeting ES6 when by default, TypeScript targets ES5. Your suggestion is only valid if someone is loading es6-shim at runtime, which the OP did not state.

Your suggestion is only valid if someone is loading es6-shim at runtime, which the OP did not state.

Well you may not have whole es6-shim as dependency if you are targeting some platfroms that support in this case Promise (but not ES6), installing just types will allow to use Promise with typescript that compiles to ES5.

for future searches.

the default library that the compiler injects in a compilation is one for ES5 runtimes. Promise was added in ES6/ES2015 . So:

  • If you know your engine has support of ES6 promises, e.g. node v4+, use --lib es6 (or --lib dom,es6 for websites).
  • if you are including a shim for promise, e.g. core-js, es6-shims, etc.. then npm install @types/core-js or npm install @types/es6-shim
  • if you are using a different library for your promise, e.g. bluebird, then you should not be using the global Promise directly.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

weswigham picture weswigham  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

seanzer picture seanzer  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

manekinekko picture manekinekko  ·  3Comments