diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts
index b790ed08fbe08..9d3d21b09b746 100644
--- a/src/compiler/commandLineParser.ts
+++ b/src/compiler/commandLineParser.ts
@@ -236,6 +236,7 @@ const libEntries: [string, string][] = [
["esnext.object", "lib.esnext.object.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.regexp", "lib.esnext.regexp.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 8ffbcd4811b55..4d255b05b05c4 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]>;
+ [Symbol.iterator](): BuiltinIterator<[string, string]>;
/**
* Returns an iterator allowing to go through all key/value pairs contained in this object.
*/
- entries(): IterableIterator<[string, string]>;
+ entries(): BuiltinIterator<[string, string]>;
/**
* 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]>;
+ entries(): BuiltinIterator<[number, Node]>;
/**
* 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]>;
+ entries(): BuiltinIterator<[number, TNode]>;
/**
* 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]>;
+ entries(): BuiltinIterator<[string, string | File]>;
/**
* 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]>;
+ entries(): BuiltinIterator<[string, string]>;
/**
* 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]>;
+ [Symbol.iterator](): BuiltinIterator<[string, string]>;
}
diff --git a/src/lib/es2015.generator.d.ts b/src/lib/es2015.generator.d.ts
index 7c6929173a0e4..952cad5b5db51 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(...args: [] | [TNext]): IteratorResult;
return(value: TReturn): IteratorResult;
diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts
index d28b8381eec86..f7f1960eb8671 100644
--- a/src/lib/es2015.iterable.d.ts
+++ b/src/lib/es2015.iterable.d.ts
@@ -27,6 +27,10 @@ interface Iterator {
throw?(e?: any): IteratorResult;
}
+interface BuiltinIterator extends Iterator {
+ [Symbol.iterator](): BuiltinIterator;
+}
+
interface Iterable {
[Symbol.iterator](): Iterator;
}
@@ -37,22 +41,22 @@ interface IterableIterator extends Iterator {
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]>;
+ entries(): BuiltinIterator<[number, T]>;
/**
* 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 {
@@ -73,67 +77,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]>;
+ entries(): BuiltinIterator<[number, T]>;
/**
* 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]>;
+ [Symbol.iterator](): BuiltinIterator<[K, V]>;
/**
* Returns an iterable of key, value pairs for every entry in the map.
*/
- entries(): IterableIterator<[K, V]>;
+ entries(): BuiltinIterator<[K, V]>;
/**
* 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]>;
+ [Symbol.iterator](): BuiltinIterator<[K, V]>;
/**
* Returns an iterable of key, value pairs for every entry in the map.
*/
- entries(): IterableIterator<[K, V]>;
+ entries(): BuiltinIterator<[K, V]>;
/**
* 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 {
@@ -149,40 +153,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]>;
+ entries(): BuiltinIterator<[T, T]>;
/**
* 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]>;
+ entries(): BuiltinIterator<[T, T]>;
/**
* 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 {
@@ -217,23 +221,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -249,19 +253,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -277,21 +281,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -307,21 +311,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -337,19 +341,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -365,19 +369,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -393,19 +397,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -421,19 +425,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 {
@@ -449,19 +453,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]>;
+ entries(): BuiltinIterator<[number, number]>;
/**
* 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 f6966264c8be4..6e3f8aacc4daf 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(...args: [] | [TNext]): Promise>;
return(value: TReturn | PromiseLike): Promise>;
diff --git a/src/lib/es2018.asynciterable.d.ts b/src/lib/es2018.asynciterable.d.ts
index 0fe799e21055e..89248f77a0171 100644
--- a/src/lib/es2018.asynciterable.d.ts
+++ b/src/lib/es2018.asynciterable.d.ts
@@ -16,6 +16,10 @@ interface AsyncIterator {
throw?(e?: any): Promise>;
}
+interface AsyncBuiltinIterator extends AsyncIterator {
+ [Symbol.asyncIterator](): AsyncBuiltinIterator;
+}
+
interface AsyncIterable {
[Symbol.asyncIterator](): AsyncIterator;
}
diff --git a/src/lib/es2020.bigint.d.ts b/src/lib/es2020.bigint.d.ts
index b4b46c7d9bb15..65455531ebd9a 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]>;
+ entries(): BuiltinIterator<[number, bigint]>;
/**
* 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]>;
+ entries(): BuiltinIterator<[number, bigint]>;
/**
* 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 bc7cf1ad5f7c3..134bf83c2770c 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 94a11768256c7..2298af614060c 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 3beaea6af8ddd..4cb8d53184ce2 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 9e601b60a27c2..7897c58cef67c 100644
--- a/src/lib/esnext.d.ts
+++ b/src/lib/esnext.d.ts
@@ -7,3 +7,4 @@
///
///
///
+///
diff --git a/src/lib/esnext.iterator.d.ts b/src/lib/esnext.iterator.d.ts
new file mode 100644
index 0000000000000..c41158e4ac40c
--- /dev/null
+++ b/src/lib/esnext.iterator.d.ts
@@ -0,0 +1,125 @@
+///
+export {};
+
+// Abstract type that allows us to mark `next` as `abstract`
+declare abstract class Iterator {
+ abstract next(value?: undefined): 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(): Array;
+
+ /**
+ * 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 d97a25e09679f..5103307c2b24b 100644
--- a/src/lib/libs.json
+++ b/src/lib/libs.json
@@ -79,6 +79,7 @@
"esnext.collection",
"esnext.array",
"esnext.regexp",
+ "esnext.iterator",
"decorators",
"decorators.legacy",
// Default libraries
diff --git a/tests/baselines/reference/YieldStarExpression4_es6.types b/tests/baselines/reference/YieldStarExpression4_es6.types
index 5a84b1bba080b..e2bec7220b371 100644
--- a/tests/baselines/reference/YieldStarExpression4_es6.types
+++ b/tests/baselines/reference/YieldStarExpression4_es6.types
@@ -6,7 +6,8 @@ function *g() {
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
yield * [];
->yield * [] : any
+>yield * [] : void
+> : ^^^^
>[] : undefined[]
> : ^^^^^^^^^^^
}
diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES6.types b/tests/baselines/reference/argumentsObjectIterator02_ES6.types
index 6c5b5eb104576..f690ea9c58855 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 71485e09f6925..8df2e79d1d5cb 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_1, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T_2[]; (iterable: Iterable | ArrayLike, mapfn: (v: T_3, k: number) => U_1, thisArg?: any): U_1[]; }
> : ^^^ ^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^^
->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_1, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T_2[]; (iterable: Iterable | ArrayLike, mapfn: (v: T_3, k: number) => U_1, thisArg?: any): U_1[]; }
> : ^^^ ^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^^
->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/bigintWithLib.errors.txt b/tests/baselines/reference/bigintWithLib.errors.txt
index aa402ec0cba5c..523b1b3732f17 100644
--- a/tests/baselines/reference/bigintWithLib.errors.txt
+++ b/tests/baselines/reference/bigintWithLib.errors.txt
@@ -5,7 +5,7 @@ bigintWithLib.ts(19,33): error TS2769: No overload matches this call.
Overload 2 of 3, '(array: Iterable): BigInt64Array', gave the following error.
Argument of type 'number[]' is not assignable to parameter of type 'Iterable'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
- Type 'IteratorResult' is not assignable to type 'IteratorResult'.
+ Type 'IteratorResult' is not assignable to type 'IteratorResult'.
Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'.
Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'.
Type 'number' is not assignable to type 'bigint'.
@@ -54,7 +54,7 @@ bigintWithLib.ts(46,26): error TS2345: Argument of type 'number' is not assignab
!!! error TS2769: Overload 2 of 3, '(array: Iterable): BigInt64Array', gave the following error.
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'Iterable'.
!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
-!!! error TS2769: Type 'IteratorResult' is not assignable to type 'IteratorResult'.
+!!! error TS2769: Type 'IteratorResult' is not assignable to type 'IteratorResult'.
!!! error TS2769: Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'.
!!! error TS2769: Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult