Typescript找不到名字'IterableIterator' [英] Typescript Cannot find name 'IterableIterator'
本文介绍了Typescript找不到名字'IterableIterator'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在typescript中的代码有问题
经过tsc编译后,我遇到的错误就是找不到一些名字。
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'.
我的代码是:
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
version tsc is Version 2.1.0-dev.20160716
推荐答案
问题是,在运行tsc -t ES6 app.ts代码编译正确后,tsc无法看到我的tsconfig.json。
Problem was that tsc cannot see my tsconfig.json, after run tsc -t ES6 app.ts code was compiled properly.
这篇关于Typescript找不到名字'IterableIterator'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文