3

I am currently trying to develop a node.js application in Visual Studio 2015 and it keeps telling me

TS2304 Cannot find the name 'Promise'

In the project settings I have ECMAScript 6 configured as build system and ES 2015 as module system.

I already tried

without success, but in the second link they say that it should work with ECMAScript version set to 6, but it changes nothing for me.

EDIT: I now did some more diagnosing. The problem seems to be that there is a mismatch between the ECMAScript Versions used by IntelliSense and the build system.

I discovered this by using more ECMAScript 6 functions, which resulted in the following IntelliSense complaint:

TS1311 Async functions are only available when targeting ECMAScript 6 and higher.

So the new question: Where do I set the ECMAScript version that IntelliSense uses?

Community
  • 1
  • 1
Andreas
  • 300
  • 5
  • 15
  • 1
    You are using `target: "es6" `? That worked for me. When trargetting `es5` I had to use the mentioned `es6-promise` library and `import {Promise} from "es6-promise" ` – Aaron Beall Mar 14 '16 at 04:04
  • Well, I have selected ECMAScript 6 in the project properties, do I need to set it somewhere else, too? – Andreas Mar 14 '16 at 18:08
  • Sounds like it, I was using `tsconfig.json` with IntelliJ IDEA. – Aaron Beall Mar 14 '16 at 18:08
  • I think I am not allowed to have a tsconfig.json file with Visual Studio. At least that is what I gather from this https://github.com/Microsoft/TypeScript/issues/3983 – Andreas Mar 14 '16 at 18:12
  • Hm, sorry not familiar with Visual Studio, sorry. Does it work from command line? – Aaron Beall Mar 14 '16 at 18:48
  • Yes, it does. It must then be a problem of Visual Studio. – Andreas Mar 15 '16 at 11:08

1 Answers1

5

This seems to be an oversight (I had the same issue). You can easily make the problem go away if you install the type definition .d.ts files.

If you are using Nuget, just install from the Package Manager console with:

PM> Install-Package es6-promise.TypeScript.DefinitelyTyped
John Weisz
  • 30,137
  • 13
  • 89
  • 132
  • I did this via typings, but it does not help. What I now noticed is that it builds fine if I press save (compile on save is active), but if I press the Start button, the compilation fails. – Andreas Mar 13 '16 at 21:41
  • 1
    @Andreas add /// at the top of your file needing Promise declaration – Gregoire Mar 15 '16 at 12:58
  • Should not be necessary when targeting ES6 anyways. – Andreas Mar 15 '16 at 20:54