Use window object in angular2, but vscode "Could not find window name"

I wrote an angular2 application in Visual Studio Code. I recently updated Visual Studio code to 1.10.2. But he highlighted window as an error. When I checked it, I found that it says:

[ts] Cannot find the 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 handle this? Thanks!

+5
source share
1 answer

In tsconfig.json make sure your library list has "dom" .

tsconfig.json should look 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

+6
source

Source: https://habr.com/ru/post/1265345/


All Articles