diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts
index b4a09ea84ba34..f0ccc291ffb90 100644
--- a/src/compiler/commandLineParser.ts
+++ b/src/compiler/commandLineParser.ts
@@ -236,6 +236,7 @@ const libEntries: [string, string][] = [
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.regexp", "lib.esnext.regexp.d.ts"],
["esnext.string", "lib.esnext.string.d.ts"],
+ ["esnext.iterator", "lib.esnext.iterator.d.ts"],
["decorators", "lib.decorators.d.ts"],
["decorators.legacy", "lib.decorators.legacy.d.ts"],
];
diff --git a/src/lib/dom.iterable.d.ts b/src/lib/dom.iterable.d.ts
index 747f279099191..da56ceae7a647 100644
--- a/src/lib/dom.iterable.d.ts
+++ b/src/lib/dom.iterable.d.ts
@@ -1,30 +1,30 @@
///
interface DOMTokenList {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface Headers {
- [Symbol.iterator](): IterableIterator<[string, string], BuiltinIteratorReturn>;
+ [Symbol.iterator](): BuiltinIterator<[string, string], BuiltinIteratorReturn>;
/**
* Returns an iterator allowing to go through all key/value pairs contained in this object.
*/
- entries(): IterableIterator<[string, string], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[string, string], BuiltinIteratorReturn>;
/**
* Returns an iterator allowing to go through all keys f the key/value pairs contained in this object.
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface NodeList {
/**
* Returns an array of key, value pairs for every entry in the list
*/
- entries(): IterableIterator<[number, Node], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, Node], BuiltinIteratorReturn>;
/**
* Performs the specified action for each node in an list.
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the list.
@@ -34,21 +34,21 @@ interface NodeList {
/**
* Returns an list of keys in the list
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the list
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface NodeListOf {
/**
* Returns an array of key, value pairs for every entry in the list
*/
- entries(): IterableIterator<[number, TNode], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, TNode], BuiltinIteratorReturn>;
/**
* Performs the specified action for each node in an list.
@@ -59,55 +59,55 @@ interface NodeListOf {
/**
* Returns an list of keys in the list
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the list
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface HTMLCollectionBase {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface HTMLCollectionOf {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface FormData {
/**
* Returns an array of key, value pairs for every entry in the list
*/
- entries(): IterableIterator<[string, string | File], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[string, string | File], BuiltinIteratorReturn>;
/**
* Returns a list of keys in the list
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns a list of values in the list
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface URLSearchParams {
/**
* Returns an array of key, value pairs for every entry in the search params
*/
- entries(): IterableIterator<[string, string], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[string, string], BuiltinIteratorReturn>;
/**
* Returns a list of keys in the search params
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns a list of values in the search params
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
/**
* iterate over key/value pairs
*/
- [Symbol.iterator](): IterableIterator<[string, string], BuiltinIteratorReturn>;
+ [Symbol.iterator](): BuiltinIterator<[string, string], BuiltinIteratorReturn>;
}
diff --git a/src/lib/es2015.generator.d.ts b/src/lib/es2015.generator.d.ts
index ac2d833b8d123..2397d79dddbd3 100644
--- a/src/lib/es2015.generator.d.ts
+++ b/src/lib/es2015.generator.d.ts
@@ -1,6 +1,6 @@
///
-interface Generator extends Iterator {
+interface Generator extends BuiltinIterator {
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
next(...[value]: [] | [TNext]): IteratorResult;
return(value: TReturn): IteratorResult;
diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts
index 98cf906c7db7c..00a0ff820ca09 100644
--- a/src/lib/es2015.iterable.d.ts
+++ b/src/lib/es2015.iterable.d.ts
@@ -35,26 +35,30 @@ interface IterableIterator extends Iterator;
}
+interface BuiltinIterator extends Iterator {
+ [Symbol.iterator](): BuiltinIterator;
+}
+
type BuiltinIteratorReturn = intrinsic;
interface Array {
/** Iterator */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an iterable of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, T], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, T], BuiltinIteratorReturn>;
/**
* Returns an iterable of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterable of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface ArrayConstructor {
@@ -75,67 +79,67 @@ interface ArrayConstructor {
interface ReadonlyArray {
/** Iterator of values in the array. */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an iterable of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, T], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, T], BuiltinIteratorReturn>;
/**
* Returns an iterable of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterable of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface IArguments {
/** Iterator */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface Map {
/** Returns an iterable of entries in the map. */
- [Symbol.iterator](): IterableIterator<[K, V], BuiltinIteratorReturn>;
+ [Symbol.iterator](): BuiltinIterator<[K, V], BuiltinIteratorReturn>;
/**
* Returns an iterable of key, value pairs for every entry in the map.
*/
- entries(): IterableIterator<[K, V], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[K, V], BuiltinIteratorReturn>;
/**
* Returns an iterable of keys in the map
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterable of values in the map
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface ReadonlyMap {
/** Returns an iterable of entries in the map. */
- [Symbol.iterator](): IterableIterator<[K, V], BuiltinIteratorReturn>;
+ [Symbol.iterator](): BuiltinIterator<[K, V], BuiltinIteratorReturn>;
/**
* Returns an iterable of key, value pairs for every entry in the map.
*/
- entries(): IterableIterator<[K, V], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[K, V], BuiltinIteratorReturn>;
/**
* Returns an iterable of keys in the map
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterable of values in the map
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface MapConstructor {
@@ -151,40 +155,40 @@ interface WeakMapConstructor {
interface Set {
/** Iterates over values in the set. */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an iterable of [v,v] pairs for every value `v` in the set.
*/
- entries(): IterableIterator<[T, T], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[T, T], BuiltinIteratorReturn>;
/**
* Despite its name, returns an iterable of the values in the set.
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterable of values in the set.
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface ReadonlySet {
/** Iterates over values in the set. */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an iterable of [v,v] pairs for every value `v` in the set.
*/
- entries(): IterableIterator<[T, T], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[T, T], BuiltinIteratorReturn>;
/**
* Despite its name, returns an iterable of the values in the set.
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an iterable of values in the set.
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface SetConstructor {
@@ -219,23 +223,23 @@ interface PromiseConstructor {
interface String {
/** Iterator */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface Int8Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Int8ArrayConstructor {
@@ -251,19 +255,19 @@ interface Int8ArrayConstructor {
}
interface Uint8Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Uint8ArrayConstructor {
@@ -279,21 +283,21 @@ interface Uint8ArrayConstructor {
}
interface Uint8ClampedArray {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Uint8ClampedArrayConstructor {
@@ -309,21 +313,21 @@ interface Uint8ClampedArrayConstructor {
}
interface Int16Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Int16ArrayConstructor {
@@ -339,19 +343,19 @@ interface Int16ArrayConstructor {
}
interface Uint16Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Uint16ArrayConstructor {
@@ -367,19 +371,19 @@ interface Uint16ArrayConstructor {
}
interface Int32Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Int32ArrayConstructor {
@@ -395,19 +399,19 @@ interface Int32ArrayConstructor {
}
interface Uint32Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Uint32ArrayConstructor {
@@ -423,19 +427,19 @@ interface Uint32ArrayConstructor {
}
interface Float32Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Float32ArrayConstructor {
@@ -451,19 +455,19 @@ interface Float32ArrayConstructor {
}
interface Float64Array {
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
/**
* Returns an array of key, value pairs for every entry in the array
*/
- entries(): IterableIterator<[number, number], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, number], BuiltinIteratorReturn>;
/**
* Returns an list of keys in the array
*/
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns an list of values in the array
*/
- values(): IterableIterator;
+ values(): BuiltinIterator;
}
interface Float64ArrayConstructor {
diff --git a/src/lib/es2018.asyncgenerator.d.ts b/src/lib/es2018.asyncgenerator.d.ts
index 15385ddabfcb0..e53975ab4021f 100644
--- a/src/lib/es2018.asyncgenerator.d.ts
+++ b/src/lib/es2018.asyncgenerator.d.ts
@@ -1,6 +1,6 @@
///
-interface AsyncGenerator extends AsyncIterator {
+interface AsyncGenerator extends AsyncBuiltinIterator {
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
next(...[value]: [] | [TNext]): Promise>;
return(value: TReturn | PromiseLike): Promise>;
diff --git a/src/lib/es2018.asynciterable.d.ts b/src/lib/es2018.asynciterable.d.ts
index 4303763db533b..17a9b067fa76f 100644
--- a/src/lib/es2018.asynciterable.d.ts
+++ b/src/lib/es2018.asynciterable.d.ts
@@ -23,3 +23,7 @@ interface AsyncIterable {
interface AsyncIterableIterator extends AsyncIterator {
[Symbol.asyncIterator](): AsyncIterableIterator;
}
+
+interface AsyncBuiltinIterator extends AsyncIterator {
+ [Symbol.asyncIterator](): AsyncBuiltinIterator;
+}
diff --git a/src/lib/es2020.bigint.d.ts b/src/lib/es2020.bigint.d.ts
index e5cafc442d677..c6ee094a332dc 100644
--- a/src/lib/es2020.bigint.d.ts
+++ b/src/lib/es2020.bigint.d.ts
@@ -153,7 +153,7 @@ interface BigInt64Array {
copyWithin(target: number, start: number, end?: number): this;
/** Yields index, value pairs for every entry in the array. */
- entries(): IterableIterator<[number, bigint], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, bigint], BuiltinIteratorReturn>;
/**
* Determines whether all the members of an array satisfy the specified test.
@@ -238,7 +238,7 @@ interface BigInt64Array {
join(separator?: string): string;
/** Yields each index in the array. */
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns the index of the last occurrence of a value in an array.
@@ -360,9 +360,9 @@ interface BigInt64Array {
valueOf(): BigInt64Array;
/** Yields each value in the array. */
- values(): IterableIterator;
+ values(): BuiltinIterator;
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
readonly [Symbol.toStringTag]: "BigInt64Array";
@@ -425,7 +425,7 @@ interface BigUint64Array {
copyWithin(target: number, start: number, end?: number): this;
/** Yields index, value pairs for every entry in the array. */
- entries(): IterableIterator<[number, bigint], BuiltinIteratorReturn>;
+ entries(): BuiltinIterator<[number, bigint], BuiltinIteratorReturn>;
/**
* Determines whether all the members of an array satisfy the specified test.
@@ -510,7 +510,7 @@ interface BigUint64Array {
join(separator?: string): string;
/** Yields each index in the array. */
- keys(): IterableIterator;
+ keys(): BuiltinIterator;
/**
* Returns the index of the last occurrence of a value in an array.
@@ -632,9 +632,9 @@ interface BigUint64Array {
valueOf(): BigUint64Array;
/** Yields each value in the array. */
- values(): IterableIterator;
+ values(): BuiltinIterator;
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
readonly [Symbol.toStringTag]: "BigUint64Array";
diff --git a/src/lib/es2020.string.d.ts b/src/lib/es2020.string.d.ts
index 7f7911d517d02..4d23b7f31941a 100644
--- a/src/lib/es2020.string.d.ts
+++ b/src/lib/es2020.string.d.ts
@@ -6,7 +6,7 @@ interface String {
* containing the results of that search.
* @param regexp A variable name or string literal containing the regular expression pattern and flags.
*/
- matchAll(regexp: RegExp): IterableIterator;
+ matchAll(regexp: RegExp): BuiltinIterator;
/** Converts all alphabetic characters to lowercase, taking into account the host environment's current locale. */
toLocaleLowerCase(locales?: Intl.LocalesArgument): string;
diff --git a/src/lib/es2020.symbol.wellknown.d.ts b/src/lib/es2020.symbol.wellknown.d.ts
index 0a65134b7c2d2..07aab68a09265 100644
--- a/src/lib/es2020.symbol.wellknown.d.ts
+++ b/src/lib/es2020.symbol.wellknown.d.ts
@@ -15,5 +15,5 @@ interface RegExp {
* containing the results of that search.
* @param string A string to search within.
*/
- [Symbol.matchAll](str: string): IterableIterator;
+ [Symbol.matchAll](str: string): BuiltinIterator;
}
diff --git a/src/lib/es2022.intl.d.ts b/src/lib/es2022.intl.d.ts
index e92a67f7a88d6..115e15a528249 100644
--- a/src/lib/es2022.intl.d.ts
+++ b/src/lib/es2022.intl.d.ts
@@ -37,7 +37,7 @@ declare namespace Intl {
containing(codeUnitIndex?: number): SegmentData;
/** Returns an iterator to iterate over the segments. */
- [Symbol.iterator](): IterableIterator;
+ [Symbol.iterator](): BuiltinIterator;
}
interface SegmentData {
diff --git a/src/lib/esnext.d.ts b/src/lib/esnext.d.ts
index 94aedd4480ccd..877f4c133c534 100644
--- a/src/lib/esnext.d.ts
+++ b/src/lib/esnext.d.ts
@@ -8,3 +8,4 @@
///
///
///
+///
diff --git a/src/lib/esnext.iterator.d.ts b/src/lib/esnext.iterator.d.ts
new file mode 100644
index 0000000000000..6a8a85eea873e
--- /dev/null
+++ b/src/lib/esnext.iterator.d.ts
@@ -0,0 +1,130 @@
+///
+
+// NOTE: This is specified as what is essentially an unreachable module. All actual global declarations can be found
+// in the `declare global` section, below. This is necessary as there is currently no way to declare an `abstract`
+// member without declaring a `class`, but declaring `class Iterator` globally would conflict with TypeScript's
+// general purpose `Iterator` interface.
+export {};
+
+// Abstract type that allows us to mark `next` as `abstract`
+declare abstract class Iterator { // eslint-disable-line @typescript-eslint/no-unsafe-declaration-merging
+ abstract next(value?: unknown): IteratorResult;
+}
+
+// Merge all members of `BuiltinIterator` into `Iterator`
+interface Iterator extends globalThis.BuiltinIterator {}
+
+// Capture the `Iterator` constructor in a type we can use in the `extends` clause of `IteratorConstructor`.
+type BuiltinIteratorConstructor = typeof Iterator;
+
+declare global {
+ // Global `BuiltinIterator` interface that can be augmented by polyfills
+ interface BuiltinIterator {
+ /**
+ * Returns this iterator.
+ */
+ [Symbol.iterator](): BuiltinIterator;
+
+ /**
+ * Creates an iterator whose values are the result of applying the callback to the values from this iterator.
+ * @param callbackfn A function that accepts up to two arguments to be used to transform values from the underlying iterator.
+ */
+ map(callbackfn: (value: T, index: number) => U): BuiltinIterator;
+
+ /**
+ * Creates an iterator whose values are those from this iterator for which the provided predicate returns true.
+ * @param predicate A function that accepts up to two arguments to be used to test values from the underlying iterator.
+ */
+ filter(predicate: (value: T, index: number) => value is S): BuiltinIterator;
+
+ /**
+ * Creates an iterator whose values are those from this iterator for which the provided predicate returns true.
+ * @param predicate A function that accepts up to two arguments to be used to test values from the underlying iterator.
+ */
+ filter(predicate: (value: T, index: number) => unknown): BuiltinIterator;
+
+ /**
+ * Creates an iterator whose values are the values from this iterator, stopping once the provided limit is reached.
+ * @param limit The maximum number of values to yield.
+ */
+ take(limit: number): BuiltinIterator;
+
+ /**
+ * Creates an iterator whose values are the values from this iterator after skipping the provided count.
+ * @param count The number of values to drop.
+ */
+ drop(count: number): BuiltinIterator;
+
+ /**
+ * Creates an iterator whose values are the result of applying the callback to the values from this iterator and then flattening the resulting iterators or iterables.
+ * @param callback A function that accepts up to two arguments to be used to transform values from the underlying iterator into new iterators or iterables to be flattened into the result.
+ */
+ flatMap(callback: (value: T, index: number) => Iterator | Iterable): BuiltinIterator;
+
+ /**
+ * Calls the specified callback function for all the elements in this iterator. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
+ * @param callbackfn A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the iterator.
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of a value from the iterator.
+ */
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T): T;
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T, initialValue: T): T;
+
+ /**
+ * Calls the specified callback function for all the elements in this iterator. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
+ * @param callbackfn A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the iterator.
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of a value from the iterator.
+ */
+ reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U;
+
+ /**
+ * Creates a new array from the values yielded by this iterator.
+ */
+ toArray(): T[];
+
+ /**
+ * Performs the specified action for each element in the iterator.
+ * @param callbackfn A function that accepts up to two arguments. forEach calls the callbackfn function one time for each element in the iterator.
+ */
+ forEach(callbackfn: (value: T, index: number) => void): void;
+
+ /**
+ * Determines whether the specified callback function returns true for any element of this iterator.
+ * @param predicate A function that accepts up to two arguments. The some method calls
+ * the predicate function for each element in this iterator until the predicate returns a value
+ * true, or until the end of the iterator.
+ */
+ some(predicate: (value: T, index: number) => unknown): boolean;
+
+ /**
+ * Determines whether all the members of this iterator satisfy the specified test.
+ * @param predicate A function that accepts up to two arguments. The every method calls
+ * the predicate function for each element in this iterator until the predicate returns
+ * false, or until the end of this iterator.
+ */
+ every(predicate: (value: T, index: number) => unknown): boolean;
+
+ /**
+ * Returns the value of the first element in this iterator where predicate is true, and undefined
+ * otherwise.
+ * @param predicate find calls predicate once for each element of this iterator, in
+ * order, until it finds one where predicate returns true. If such an element is found, find
+ * immediately returns that element value. Otherwise, find returns undefined.
+ */
+ find(predicate: (value: T, index: number) => value is S): S | undefined;
+ find(predicate: (value: T, index: number) => unknown): T | undefined;
+
+ readonly [Symbol.toStringTag]: string;
+ }
+
+ // Global `IteratorConstructor` interface that can be augmented by polyfills
+ interface IteratorConstructor extends BuiltinIteratorConstructor {
+ /**
+ * Creates a native iterator from an iterator or iterable object.
+ * Returns its input if the input already inherits from the built-in Iterator class.
+ * @param value An iterator or iterable object to convert a native iterator.
+ */
+ from(value: Iterator | Iterable): BuiltinIterator;
+ }
+
+ var Iterator: IteratorConstructor;
+}
diff --git a/src/lib/libs.json b/src/lib/libs.json
index 9477c3d78edcd..fb40b9d10dcf2 100644
--- a/src/lib/libs.json
+++ b/src/lib/libs.json
@@ -80,6 +80,7 @@
"esnext.array",
"esnext.regexp",
"esnext.string",
+ "esnext.iterator",
"decorators",
"decorators.legacy",
// Default libraries
diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES6.types b/tests/baselines/reference/argumentsObjectIterator02_ES6.types
index 4dd2e090a434c..c192ab9617b08 100644
--- a/tests/baselines/reference/argumentsObjectIterator02_ES6.types
+++ b/tests/baselines/reference/argumentsObjectIterator02_ES6.types
@@ -12,10 +12,10 @@ function doubleAndReturnAsArray(x: number, y: number, z: number): [number, numbe
> : ^^^^^^
let blah = arguments[Symbol.iterator];
->blah : () => IterableIterator
-> : ^^^^^^
->arguments[Symbol.iterator] : () => IterableIterator
-> : ^^^^^^
+>blah : () => BuiltinIterator
+> : ^^^^^^
+>arguments[Symbol.iterator] : () => BuiltinIterator
+> : ^^^^^^
>arguments : IArguments
> : ^^^^^^^^^^
>Symbol.iterator : unique symbol
@@ -33,10 +33,10 @@ function doubleAndReturnAsArray(x: number, y: number, z: number): [number, numbe
for (let arg of blah()) {
>arg : any
->blah() : IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^^^
->blah : () => IterableIterator
-> : ^^^^^^
+>blah() : BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+>blah : () => BuiltinIterator
+> : ^^^^^^
result.push(arg + arg);
>result.push(arg + arg) : number
diff --git a/tests/baselines/reference/arrayFrom.types b/tests/baselines/reference/arrayFrom.types
index d8c53ad231cb4..8829708cedd67 100644
--- a/tests/baselines/reference/arrayFrom.types
+++ b/tests/baselines/reference/arrayFrom.types
@@ -83,14 +83,14 @@ const result2: A[] = Array.from(inputA.values());
> : ^^^^^^^^^^^^^^^^
>from : { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^^
->inputA.values() : IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^
->inputA.values : () => IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^^^^^^^
+>inputA.values() : BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+>inputA.values : () => BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>inputA : A[]
> : ^^^
->values : () => IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^^^^^^^
+>values : () => BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
const result3: B[] = Array.from(inputA.values()); // expect error
>result3 : B[]
@@ -103,14 +103,14 @@ const result3: B[] = Array.from(inputA.values()); // expect error
> : ^^^^^^^^^^^^^^^^
>from : { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^^
->inputA.values() : IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^
->inputA.values : () => IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^^^^^^^
+>inputA.values() : BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+>inputA.values : () => BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>inputA : A[]
> : ^^^
->values : () => IterableIterator
-> : ^^^^^^^^^^^^^^^^^^^^^^^^^
+>values : () => BuiltinIterator
+> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b }));
>result4 : A[]
diff --git a/tests/baselines/reference/asyncYieldStarContextualType.types b/tests/baselines/reference/asyncYieldStarContextualType.types
index 1a74d90e887fe..fa37a8b0c9b11 100644
--- a/tests/baselines/reference/asyncYieldStarContextualType.types
+++ b/tests/baselines/reference/asyncYieldStarContextualType.types
@@ -1,5 +1,9 @@
//// [tests/cases/compiler/asyncYieldStarContextualType.ts] ////
+=== Performance Stats ===
+Type Count: 1,000
+Instantiation count: 2,500
+
=== asyncYieldStarContextualType.ts ===
// https://github.com/microsoft/TypeScript/issues/57903
interface Result {
diff --git a/tests/baselines/reference/builtinIterator.errors.txt b/tests/baselines/reference/builtinIterator.errors.txt
new file mode 100644
index 0000000000000..26749ea24a683
--- /dev/null
+++ b/tests/baselines/reference/builtinIterator.errors.txt
@@ -0,0 +1,164 @@
+builtinIterator.ts(38,1): error TS2511: Cannot create an instance of an abstract class.
+builtinIterator.ts(40,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member next from class 'Iterator'.
+builtinIterator.ts(44,3): error TS2416: Property 'next' in type 'BadIterator1' is not assignable to the same property in base type 'Iterator'.
+ Type '() => { readonly done: false; readonly value: 0; } | { readonly done: true; readonly value: "a string"; }' is not assignable to type '(value?: unknown) => IteratorResult'.
+ Type '{ readonly done: false; readonly value: 0; } | { readonly done: true; readonly value: "a string"; }' is not assignable to type 'IteratorResult'.
+ Type '{ readonly done: true; readonly value: "a string"; }' is not assignable to type 'IteratorResult'.
+ Type '{ readonly done: true; readonly value: "a string"; }' is not assignable to type 'IteratorReturnResult'.
+ Types of property 'value' are incompatible.
+ Type '"a string"' is not assignable to type 'undefined'.
+builtinIterator.ts(54,3): error TS2416: Property 'next' in type 'BadIterator2' is not assignable to the same property in base type 'Iterator'.
+ Type '() => { done: boolean; value: number; }' is not assignable to type '(value?: unknown) => IteratorResult'.
+ Type '{ done: boolean; value: number; }' is not assignable to type 'IteratorResult'.
+ Type '{ done: boolean; value: number; }' is not assignable to type 'IteratorYieldResult'.
+ Types of property 'done' are incompatible.
+ Type 'boolean' is not assignable to type 'false'.
+builtinIterator.ts(60,3): error TS2416: Property 'next' in type 'BadIterator3' is not assignable to the same property in base type 'Iterator'.
+ Type '() => { done: boolean; value: number; } | { done: boolean; value: string; }' is not assignable to type '(value?: unknown) => IteratorResult'.
+ Type '{ done: boolean; value: number; } | { done: boolean; value: string; }' is not assignable to type 'IteratorResult'.
+ Type '{ done: boolean; value: number; }' is not assignable to type 'IteratorResult'.
+ Type '{ done: boolean; value: number; }' is not assignable to type 'IteratorYieldResult'.
+ Types of property 'done' are incompatible.
+ Type 'boolean' is not assignable to type 'false'.
+builtinIterator.ts(70,29): error TS2345: Argument of type 'Generator' is not assignable to parameter of type 'Iterator | Iterable'.
+ Type 'Generator' is not assignable to type 'Iterator'.
+ Types of property 'next' are incompatible.
+ Type '(...[value]: [] | [boolean]) => IteratorResult' is not assignable to type '(...[value]: [] | [undefined]) => IteratorResult