LoginSignup
2

More than 5 years have passed since last update.

angular-cli@v1.0.0-rc.0になってVS Codeがエラーだらけになった

Last updated at Posted at 2017-02-27

angular-cli@v1.0.0-rc.0になってVS Codeがエラーだらけになった

2017/02/25に@angular/cliのrcがリリースされた。
今まで何もエラー表示がなかったソースがエラー表示だらけになってしまった。
いろいろ設定を変え元に戻るまでの備忘録。

エラー表示になった箇所

~~~.service.ts
handleKeyboardEvent(event: KeyboardEvent): number { } // ←[ts] Cannot find name 'KeyboardEvent'.
handleMouseMoveEvent(event: MouseEvent): number { } // ←[ts] Cannot find name 'MouseEvent'.
constructor( @Inject('Window') private window: Window) { } // ←[ts] Cannot find name 'Window'.

上記のエラーはエディター上はエラーになっているが、ng build, ng serve, ng testでは
エラーにならずにちゃんと通る。
原因は@angular/cli@v1.0.0-rc.0からtsconfig.jsonが分割されたことによって
VSCodeが読み込む設定のlibにdomが含まれていないのが原因だった。

tsconfig.json
{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "target": "es2016",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016", "dom"←!!!ここにdomを追記する!!!
    ]
  }
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2