3

I added the systemjs.d.ts file to my project in WebStorm IDE. This file includes two uses of the class Promise, which are marked as errors by TSC. This is extremely weird because I've already added the es6-promise.d.ts file to my project, and it does solve the same problem for the mongodb.d.ts file. So why in one file it's recognized and in the other it's not? All the .d.ts files are located in the same foler (root-folder\DefinitelyTyped).

The errors I get:

TS2304: Cannot find name 'Promise'

systemjs.d.ts: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/systemjs/systemjs.d.ts

Any help will be profoundly appreciated!

Alon
  • 10,381
  • 23
  • 88
  • 152
  • can you post your systemjs config? – Nick Acosta Jun 29 '16 at 22:05
  • @Nick Acosta I don't have a systemjs config yet and I don't think it matters because we're talking about compile-time, not about run-time. I won't have a systemjs config before the definitelytyped of the library itself is compiled. – Alon Jun 29 '16 at 22:14
  • Can you post some code then? Or maybe a plnkr? – Nick Acosta Jun 29 '16 at 22:17
  • @Nick Acosta I added a link to systemjs.d.ts. Notice that nothing here is my code. It's all definitelytyped files. – Alon Jun 29 '16 at 22:23
  • How about your tsconfig? The more info you provide the better :) – Nick Acosta Jun 29 '16 at 22:24
  • @Nick Acosta I don't have a tsconfig file. Instead I have command line options: -m commonjs -t ES5 – Alon Jun 29 '16 at 22:26
  • http://stackoverflow.com/questions/27573365/how-to-use-typescript-with-native-es6-promises – Nick Acosta Jun 29 '16 at 22:35
  • Are you able to transpile to es6? That should make the error go away, as reported by other users. – Nick Acosta Jun 30 '16 at 06:16
  • @Nick Acosta I need to transpile my ts to es5. Anyways I solved it. You can see my self answer below. Thank you for your time. – Alon Jun 30 '16 at 11:32
  • Possible duplicate of [Angular 2 can't find Promise,Map,Set and Iterator](http://stackoverflow.com/questions/35660498/angular-2-cant-find-promise-map-set-and-iterator) – Niels Steenbeek Jan 12 '17 at 11:57

2 Answers2

3

I solved it. I forgot to add a reference comment.

Adding the following line to the beginning of the file solved the problem:

/// <reference path='es6-promise.d.ts' />
Alon
  • 10,381
  • 23
  • 88
  • 152
0

es6-promise.d.ts file to my project

if this file https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/es6-promise/es6-promise.d.ts is included in your project then in should just work.

you can try --listFiles command line to see if tsc picked it up.

More

Alm.tools highlights the files in the compilation context in the tree view ;)

basarat
  • 261,912
  • 58
  • 460
  • 511
  • I have the correct es6-promise.d.ts file. It was a weird problem because in mongodb.d.ts file Promise is recognized. Anyways I solved it: I just forgot to add a reference comment to the beginning of systemjs.d.ts file. Thank you for your time. – Alon Jun 30 '16 at 11:29