Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Cannot find name 'IterableIterator'

I have problem with my code in typescript After compile by tsc, I have errors like about cannot find some 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());

version tsc is Version 2.1.0-dev.20160716

like image 692
Marcin Pruciak Avatar asked Jul 17 '16 11:07

Marcin Pruciak


2 Answers

Problem was that tsc cannot see my tsconfig.json, after run tsc -t ES6 app.ts code was compiled properly.

like image 158
Marcin Pruciak Avatar answered Nov 16 '22 06:11

Marcin Pruciak


I solve the same problem with tsc -v 3.5.3 and @types/node (tested es5 and es6)

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

and add "node" in the tsconfig.json

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

Take a look here DefinitelyTyped for complete node types.

like image 29
Shim-Sao Avatar answered Nov 16 '22 04:11

Shim-Sao