最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use window object in angular2 but vscode "Cannot find name 'window' " - Stack Ove

programmeradmin0浏览0评论

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

How can I deal with this? Thank you!

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

How can I deal with this? Thank you!

Share Improve this question edited Mar 15, 2017 at 10:19 Angelos Chalaris 6,7078 gold badges53 silver badges80 bronze badges asked Mar 12, 2017 at 8:07 yilihjyyilihjy 731 silver badge4 bronze badges 1
  • Try to add options "lib": [ "es2015", "dom" ], in your tsconfig.json – yurzui Commented Mar 12, 2017 at 8:14
Add a ment  | 

1 Answer 1

Reset to default 9

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

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

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

Compiler options

发布评论

评论列表(0)

  1. 暂无评论