Hardipsinh Jadeja
Hardipsinh Jadeja

Reputation: 1297

Cannot find name 'Promise' in visual studio code

I am using Angular2 with Visual studio code. In visual studio code It shows me error as shown below :

enter image description here

As seen in the image Promise is highlighted with red underline. Also I have another query is if we define inline function then Visual studio code will also shows red underline below the name of function. Like response is shown with red underline in above image.

However my code works fine in browser. but in VS Code it shows me red underline.

I don't want any red underline in my code. Is it possible ? Can anyone help me to resolve this ?

Upvotes: 9

Views: 3005

Answers (2)

Anavar Bharmal
Anavar Bharmal

Reputation: 329

As the visual studio has functionality for visible intellisense for any language, you can just add the typings.json file in root level and add below code to it.

-- your typings.json

{
  "globalDependencies": {
    "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459"
  }
}

and just hit the below command in cmd to current working project directory (install typings globally(-g) if not installed on your machine).

typings install

So only in visual studio, you will get the intellisense and remove the error.

Upvotes: 1

Joel Almeida
Joel Almeida

Reputation: 8047

One solution is to install the typings of es6-shim.

First install typings with:

npm install typings --global

Install the es6-shim typings with:

typings install es6-shim --save

You should have a typings folder now, with es6-shim.d.ts.

If you don't have a jsconfig.json file you will need to reference those typings by placing this on the top of your file:

/// <reference path='./path/to/typings' />

Upvotes: 1

Related Questions