Closed
Description
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 number
s; 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.