7

I wrote an angular2 app in Visual studio code. Recently, I updated Visual Studio Code to 1.10.2. But it has highlighted window as having an error. When I checked it, I found that it says:

[ts] Cannot find name 'window'.

My code is as follows:

saveCustomIndex(customIndex:any,indexName:string){
    window.localStorage.setItem(indexName,JSON.stringify(customIndex));
}

Screenshot

Problem screenshot

How can I deal with this? Thank you!

1
  • Try to add options "lib": [ "es2015", "dom" ], in your tsconfig.json Commented Mar 12, 2017 at 8:14

1 Answer 1

9

On tsconfig.json, make sure to have "dom" on your list of libraries.

tsconfig.json should be looking more or less like this:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

Compiler options

Sign up to request clarification or add additional context in comments.

1 Comment

it's exist, but i still have this error message everytime I try to build (ng build) : "Cannot find name '$window'. Did you mean 'Window'?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.