Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio code showing error "Can't find name Date"

I am working on a basic Angular project with Visual studio code(Version 1.19.2) as my IDE.

The following piece of code is working fine but VSC doesn't seem to be happy about it.

It is showing error when i use new Date() or JSON.stringify

enter image description here

But the end results are correct and the console prints fine.

enter image description here

How to remove this error from Visual studio code?


Update 1

Here are my dependencies

  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "~7.0.3",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/language-service": "~7.0.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  }
like image 307
Abdullah Khan Avatar asked Sep 20 '25 15:09

Abdullah Khan


1 Answers

My Visual studio code was using Typescript v2.6.2.

As mentioned by @Jai I updated the VSC's typescript version to match the Typescript version of my Angular project, which in my case was Typescript v3.1.1.

To update the typescript version

Step 1. Simply click on the version displayed in the footer of your visual studio code.

Step 2. Then choose Use Workspace version.

You will be good to go.

enter image description here

PS: Special thanks to @Jai.

like image 189
Abdullah Khan Avatar answered Sep 22 '25 09:09

Abdullah Khan