当我在TypeScript上使用yield*表达式时,它总是会出错.
类型'IterableIterator'不是数组类型.
如何正确设置类型而不使用any以避免错误?
function* g1(): IterableIterator<number> {
yield 2;
yield 3;
yield 4;
}
function* g2(): IterableIterator<number> {
yield 1;
// ERROR: Type 'IterableIterator<number>' is not an array type.
yield* g1();
yield 5;
}
const iterator = g2();
Run Code Online (Sandbox Code Playgroud) typescript ×1