我的 typescript 代码有问题 通过 tsc 编译后,出现类似 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'.
我的代码是:
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 是版本 2.1.0-dev.20160716
最佳答案
问题是 tsc 看不到我的 tsconfig.json,在运行 tsc -t ES6 app.ts 代码被正确编译后。
关于javascript - typescript 找不到名称 'IterableIterator',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38420846/