错误 TS2304:在Angular 4项目的app.components.ts和main.ts文件中找不到名称'X'。

5

我刚开始接触 TypeScript。使用的是 neovim、ubuntu 16.04 及其各种 vim typescript 插件 tsuquyomileafgarland/typescript-vimmhartington/nvim-typescript,我相信我已经正确配置好了它们。

我已经成功安装了 @angular/cli,并尝试完成教程,但是我遇到了一个我不理解的错误。

`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.`

我尝试过各种方法,包括尝试以下的tsconfig文件Glob属性:
"filesGlob": [ "main.ts", "typings.d.ts", "app/**/*.ts", "!app/**/*.spec.ts" ],

安装Angular / Core-js和@types / core-js和typings
npm install --save-dev @types/core-js
npm install @types/node --save 

编辑后的tsconfig.json文件
{
  "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"
    ]
  }
}

我也编辑了 tsconfig.app.json 文件。

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

然而,尽管进行了所有这些更改,我的app.components.ts文件和main.ts仍存在错误。

2个回答

0
在你的tsconfig.json文件中,在"compilerOptions"中添加"skipLibCheck": true

不做任何更改。 - Y. Leonce Eyog

0
我在上述文件的开头添加了以下行,问题似乎已经解决。
///<reference path="../../node_modules/typescript/lib/lib.es6.d.ts"/>

我担心的问题来自于它将lib设置为es6,我无法理解实际上是什么导致了我的问题。任何提示都将不胜感激。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接