Acknowledgement
Comment
#58243 introduced the BuiltinIteratorReturn type and used it everywhere in type definition.
Then #58222 introduced the BuiltinIterator type and replaced some IterableIterator usage with BuiltinIterator.
I wonder if BuiltinIteratorReturn could be set to the default type argument of the TReturn type parameter of BuiltinIterator, e.g.:
// lib.es2015.iterable.d.ts
interface BuiltinIterator<T, TReturn = BuiltinIteratorReturn, TNext = any> extends Iterator<T, TReturn, TNext> {
[Symbol.iterator](): BuiltinIterator<T, TReturn, TNext>;
}
#58463 mentions that BuiltinIteratorReturn cannot be used for IterableIterator because IterableIterator is a general purpose type not only for built-in iterators. However, this doesn't apply to BuiltinIterator. I think we can safely use BuiltinIteratorReturn specifically for BuiltinIterator's default type argument.
The downside of current approach (specify BuiltinIteratorReturn everywhere) is that it is too easy to disable the benefit of the new compiler option by manually using the BuiltinIterator type:
const nums = new Set([1, 2, 3, 4, 5]);
// oops! This is BuiltinIterator<number, any, any> regardless of compiler option
const values: BuiltinIterator<number> = nums.values();
Acknowledgement
Comment
#58243 introduced the
BuiltinIteratorReturntype and used it everywhere in type definition.Then #58222 introduced the
BuiltinIteratortype and replaced someIterableIteratorusage withBuiltinIterator.I wonder if
BuiltinIteratorReturncould be set to the default type argument of theTReturntype parameter ofBuiltinIterator, e.g.:#58463 mentions that
BuiltinIteratorReturncannot be used forIterableIteratorbecauseIterableIteratoris a general purpose type not only for built-in iterators. However, this doesn't apply toBuiltinIterator. I think we can safely useBuiltinIteratorReturnspecifically forBuiltinIterator's default type argument.The downside of current approach (specify
BuiltinIteratorReturneverywhere) is that it is too easy to disable the benefit of the new compiler option by manually using theBuiltinIteratortype: