Courtesy of @bterlson (and his idea in general)
interface Foo<T> extends IterableIterator<T> {
next(valueGivenWhenYieldExpressionIsUsed: number)
}
This type is basically an IterableIterator except that it restricts the types of values a consumer can pass through to next.
function* foo(): Foo<string> {
let x = yield "hello";
console.log(x);
}
let gen = foo();
gen.next(100);
gen.next(200);
Here, calls to next can only accept numbers; however, the yield expressions in the generator are just typed as any.
Since we have an explicit type, we should just figure the type of yield expressions out from that.
Courtesy of @bterlson (and his idea in general)
This type is basically an
IterableIteratorexcept that it restricts the types of values a consumer can pass through tonext.Here, calls to
nextcan only acceptnumbers; however, the yield expressions in the generator are just typed asany.Since we have an explicit type, we should just figure the type of
yieldexpressions out from that.