Typescript Cannot find the name 'IterableIterator'

I have a problem with my typescript code. After compiling with tsc, I have errors, for example, that they cannot find names.

app.ts(1,22): error TS2304: Cannot find name 'IterableIterator'. app.ts(8,20): error TS2304: Cannot find name 'IteratorResult'. app.ts(26,6): error TS2304: Cannot find name 'Symbol'. app.ts(26,26): error TS2304: Cannot find name 'IterableIterator'. 

My code is:

 class Fib implements IterableIterator<number> { protected fn1 = 0; protected fn2 = 1; constructor(protected maxValue?: number) {} public next(): IteratorResult<number> { var current = this.fn1; this.fn1 = this.fn2; this.fn2 = current + this.fn1; if (this.maxValue && current <= this.maxValue) { return { done: false, value: current } } return { done: true } } [Symbol.iterator](): IterableIterator<number> { eturn this; } } fib = new Fib(); console.log(fib.next()); 

tsc version - Version 2.1.0-dev.20160716

+9
javascript typescript
source share
2 answers

The problem was that tsc cannot see my tsconfig.json, after running tsc -t ES6 the app.ts code was compiled properly.

+9
source share

I have tsc -v 3.5.3 the same problem with tsc -v 3.5.3 and @types/node (checked by es5 and es6)

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

and add "node" to tsconfig.json

 "compilerOptions": { "types": [ "./", "node" ] } 

Take a look here for DefinitiveTyped for complete node types.

0
source share

All Articles