⚙ Compilation target
ESNext
⚙ Library
esnext.iterator.d.ts
Missing / Incorrect Definition
The return method always exists on iterators returned by Iterator.from (iter in below code) and iterators returned by Iterator Helpers methods (iter2 in below code).
However, it is defined as optional in the current definition. This could be improved.
Please note that you can't just add a non-optional return method definition to the IteratorObject type -- iterators returned by builtin methods other than Iterator Helpers don't have that method (iter3).
P.S. if you are interested in a motivating example, I don't have one. Sorry 🤪
Sample Code
const iter = Iterator.from({ next() { return { done: false, value: 0 }} });
iter.return(); // should not error
const iter2 = iter.map(x => x);
iter2.return(); // should not error
const iter3 = [].values();
iter3.return(); // Note: this error IS correct
Playground
Documentation Link
https://tc39.es/proposal-iterator-helpers/
Spec states that below objects always have the return method:
- %WrapForValidIteratorPrototype%
- %IteratorHelperPrototype%
⚙ Compilation target
ESNext
⚙ Library
esnext.iterator.d.ts
Missing / Incorrect Definition
The
returnmethod always exists on iterators returned byIterator.from(iterin below code) and iterators returned by Iterator Helpers methods (iter2in below code).However, it is defined as optional in the current definition. This could be improved.
Please note that you can't just add a non-optional
returnmethod definition to theIteratorObjecttype -- iterators returned by builtin methods other than Iterator Helpers don't have that method (iter3).P.S. if you are interested in a motivating example, I don't have one. Sorry 🤪
Sample Code
Playground
Documentation Link
https://tc39.es/proposal-iterator-helpers/
Spec states that below objects always have the
returnmethod: