我想在打字稿中使用生成器功能。但是,編譯器會引發錯誤如何在打字稿中使用生成器功能
error TS2339: Property 'next' does not exist on type
下面是我的代碼的最接近樣品。
export default class GeneratorClass {
constructor() {
this.generator(10);
this.generator.next();
}
*generator(count:number): Iterable<number | undefined> {
while(true)
yield count++;
}
}
Here is the playground link for the same
您是否在操場上試過這個,它有相同的結果錯誤TS2339:類型 – anandaravindan
@anandaravindan上不存在屬性'next':將類型從'Iterable'更改爲'Iterator'。 –
@FelixKling Thankyou。剛剛檢查過文檔,返回類型是IterableIterator。 – anandaravindan