-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
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();