Closed
Description
Search Terms
Iterator.next() type, yield expression type
Suggestion
Type Iterator.next()
/yield
. I suggest Iterator<A, B>, where A
is the input type, and B
is the output type.
Mentioned in #10148 and #14883.
Required by #32283.
Alternative proposal in #32523, those this requires more drastic changes to TypeScript's type model.
Use Cases
Pretty self-explanatory; I want typed expressions. It's why I use TypeScript.
And currently, all yield ...
expressions have no typing. (They are typed as any
).
Examples
function* totalLength() {
let result = 0;
while (true) {
result += (yield result).length;
}
const t = totalLength();
t.next('abc'); // 0
t.next('def'); // 3
t.return(''); // 6
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.