Angular4 What definition of Iterable should I use

拈花ヽ惹草 提交于 2019-11-27 08:35:51

问题


I have upgraded my app to the latest Angular 4 (beta-8) version. However I keep having the following error :

@angular\core\src\change_detection\differs\iterable_differs.d.ts:14: TS2304 Cannot find name 'Iterable'

I did look up the changelog and found :

A definition of Iterable<T> is now required to correctly compile Angular applications. Support for Iterable<T> is not required at runtime but a type definition Iterable<T> must be available.

What should I use as Iterable definition here ?

EDIT:

tsconfig.json

"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    /* for reading your ts source while debugging from a browser */
    "sourceMap": true,
    /* the following two settings are required for angular2 annotations to work*/
    "emitDecoratorMetadata": true,
    "experimentalDecorators":true,
    /* noImplicitAny when you want your typescript to be fully typed */
    "noImplicitAny":false,
    "suppressImplicitAnyIndexErrors":true,
    "noFallthroughCasesInSwitch":true,
    "noImplicitReturns":true,
    "outDir": "./target/ts"
  }

回答1:


Following the migration stated in their changelog you should add es2015.iterable as a lib inside your tsconfig.json:

{
  ...,
  "compilerOptions" : {
     ...,
     "lib": ["es6", "dom", "es2015.iterable"]
   }
}



回答2:


I tried the accepted answer for this question but it didn't work in my case.

In my case I added below line in my main.ts

///<reference path="./../typings/globals/core-js/index.d.ts"/>

which fixed the issue, hope this helps someone.



来源:https://stackoverflow.com/questions/42347142/angular4-what-definition-of-iterable-should-i-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!