Error TS2304: Cannot find name 'X' in the app.components.ts and main.ts file of angular 4 project

Viewed 1197

new to typescript. Using neovim, ubuntu 16.04 and the various vim typescript plugins tsuquyomi, leafgarland/typescript-vim, mhartington/nvim-typescript, and I'm pretty sure I configured them correctly.

I have installed the @angular/cli successfully and I'm trying to complete the tutorial but I have an error which I do not understand.

`1 .._modules/@angular/core/src/change_detection/differs/default_iterable_differ.d.ts|| TS2304: Cannot find name 'Iterable'. 
   2 ../node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts|| TS2304: Cannot find name 'Map'.
   3 ../node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts|| TS2304: Cannot find name 'Map'.
   4 ../node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts|| TS2304: Cannot find name 'Iterable'.
   5 damn/node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts|| TS2304: Cannot find name 'Map'.
   6 ..//node_modules/@angular/core/src/di/reflective_provider.d.ts|| TS2304: Cannot find name 'Map'.
   7 ../node_modules/@angular/core/src/di/reflective_provider.d.ts|| TS2304: Cannot find name 'Map'.
   8 ../node_modules/rxjs/Observable.d.ts|| TS2693: 'Promise' only refers to a type, but is being used as a value here.`

I tried everything I guess, from

trying the following tsconfig filesGlob property :

"filesGlob": [ "main.ts", "typings.d.ts", "app/**/*.ts", "!app/**/*.spec.ts" ],

to intalling angular/core-js and @types/core-js and typings

npm install --save-dev @types/core-js
npm install @types/node --save 

The edited tsconfig.json file

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "types": ["node"],
    "typeRoots": [
      "node_modules/@types"
    ],
    "files": [
  "main.ts",
  "typings.d.ts"
],
"filesGlob": [
  "main.ts",
  "typings.d.ts",
  "app/**/*.ts"  
],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

I also edited the tsconfig.app.json file

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": [],
    "typeRoots": [
"../node_modules/@types/"
    ]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

However, the errors are still there in my app.components.ts file and the main.ts depspite all these changes.

2 Answers

I included the following line at the beginning of the aforementioned files and the problem seems to be resolved.

///<reference path="../../node_modules/typescript/lib/lib.es6.d.ts"/>

The concern I have comes from the fact that it sets the lib to es6 and I fail to understand what is actually causing my problem. Any hints will be gladly appreciated.

Related