interface SymbolConstructor { readonly iterator: unique symbol; readonly asyncIterator: unique symbol; } type IteratorYieldResult = { done?: false; } & (TReturn extends undefined ? { value?: undefined; } : { value: TReturn; }); type IteratorReturnResult = { done: true } & (TReturn extends undefined ? { value?: undefined; } : { value: TReturn; }); type IteratorResult = IteratorYieldResult | IteratorReturnResult; interface Iterator { next(...args: [] | [TNext]): IteratorResult; return?(value?: TReturn): IteratorResult; throw?(e?: any): IteratorResult; } interface Iterable { [Symbol.iterator](): Iterator; } interface IterableIterator extends Iterator { [Symbol.iterator](): IterableIterator; } interface Generator extends Iterator { // 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; throw(e: any): IteratorResult; [Symbol.iterator](): Generator; } interface GeneratorFunction { /** * Creates a new Generator object. * @param args A list of arguments the function accepts. */ new (...args: any[]): Generator; /** * Creates a new Generator object. * @param args A list of arguments the function accepts. */ (...args: any[]): Generator; /** * The length of the arguments. */ readonly length: number; /** * Returns the name of the function. */ readonly name: string; /** * A reference to the prototype. */ readonly prototype: Generator; } interface GeneratorFunctionConstructor { /** * Creates a new Generator function. * @param args A list of arguments the function accepts. */ new (...args: string[]): GeneratorFunction; /** * Creates a new Generator function. * @param args A list of arguments the function accepts. */ (...args: string[]): GeneratorFunction; /** * The length of the arguments. */ readonly length: number; /** * Returns the name of the function. */ readonly name: string; /** * A reference to the prototype. */ } interface AsyncIterator { // 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 | Thenable): Promise>; throw?(e?: any): Promise>; } interface AsyncIterable { [Symbol.asyncIterator](): AsyncIterator; } interface AsyncIterableIterator extends AsyncIterator { [Symbol.asyncIterator](): AsyncIterableIterator; } interface AsyncGenerator extends AsyncIterator { // 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 | Thenable): Promise>; throw(e: any): Promise>; [Symbol.asyncIterator](): AsyncGenerator; } interface AsyncGeneratorFunction { /** * Creates a new AsyncGenerator object. * @param args A list of arguments the function accepts. */ new (...args: any[]): AsyncGenerator; /** * Creates a new AsyncGenerator object. * @param args A list of arguments the function accepts. */ (...args: any[]): AsyncGenerator; /** * The length of the arguments. */ readonly length: number; /** * Returns the name of the function. */ readonly name: string; /** * A reference to the prototype. */ readonly prototype: AsyncGenerator; } interface AsyncGeneratorFunctionConstructor { /** * Creates a new AsyncGenerator function. * @param args A list of arguments the function accepts. */ new (...args: string[]): AsyncGeneratorFunction; /** * Creates a new AsyncGenerator function. * @param args A list of arguments the function accepts. */ (...args: string[]): AsyncGeneratorFunction; /** * The length of the arguments. */ readonly length: number; /** * Returns the name of the function. */ readonly name: string; /** * A reference to the prototype. */ readonly prototype: AsyncGeneratorFunction; } interface Array extends IterableIterator { entries(): IterableIterator<[number, T]>; values(): IterableIterator; keys(): IterableIterator; } setProps(Symbol, { iterator: Symbol("Symbol.iterator") as any, asyncIterator: Symbol("Symbol.asyncIterator") as any, }); setProps(Array.prototype, { [Symbol.iterator]: function() { return this.values(); }, values() { var i = 0; return { next: () => { while (i < this.length) { if (i++ in this) return { done: false, value: this[i - 1] }; } return { done: true, value: undefined }; }, [Symbol.iterator]() { return this; } }; }, keys() { var i = 0; return { next: () => { while (i < this.length) { if (i++ in this) return { done: false, value: i - 1 }; } return { done: true, value: undefined }; }, [Symbol.iterator]() { return this; } }; }, entries() { var i = 0; return { next: () => { while (i < this.length) { if (i++ in this) return { done: false, value: [i - 1, this[i - 1]] }; } return { done: true, value: undefined }; }, [Symbol.iterator]() { return this; } }; }, });