1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation. All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4this file except in compliance with the License. You may obtain a copy of the
5License at http://www.apache.org/licenses/LICENSE-2.0
6
7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10MERCHANTABLITY OR NON-INFRINGEMENT.
11
12See the Apache Version 2.0 License for specific language governing permissions
13and limitations under the License.
14***************************************************************************** */
15
16
17
18/// <reference no-default-lib="true"/>
19
20
21/// <reference lib="es2015.symbol" />
22
23interface SymbolConstructor {
24    /**
25     * A method that returns the default iterator for an object. Called by the semantics of the
26     * for-of statement.
27     */
28    readonly iterator: symbol;
29}
30
31interface IteratorYieldResult<TYield> {
32    done?: false;
33    value: TYield;
34}
35
36interface IteratorReturnResult<TReturn> {
37    done: true;
38    value: TReturn;
39}
40
41type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
42
43interface Iterator<T, TReturn = any, TNext = undefined> {
44    // NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
45    next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
46    return?(value?: TReturn): IteratorResult<T, TReturn>;
47    throw?(e?: any): IteratorResult<T, TReturn>;
48}
49
50interface Iterable<T> {
51    [Symbol.iterator](): Iterator<T>;
52}
53
54interface IterableIterator<T> extends Iterator<T> {
55    [Symbol.iterator](): IterableIterator<T>;
56}
57
58interface Array<T> {
59    /** Iterator */
60    [Symbol.iterator](): IterableIterator<T>;
61
62    /**
63     * Returns an iterable of key, value pairs for every entry in the array
64     */
65    entries(): IterableIterator<[number, T]>;
66
67    /**
68     * Returns an iterable of keys in the array
69     */
70    keys(): IterableIterator<number>;
71
72    /**
73     * Returns an iterable of values in the array
74     */
75    values(): IterableIterator<T>;
76}
77
78interface ArrayConstructor {
79    /**
80     * Creates an array from an iterable object.
81     * @param iterable An iterable object to convert to an array.
82     */
83    from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
84
85    /**
86     * Creates an array from an iterable object.
87     * @param iterable An iterable object to convert to an array.
88     * @param mapfn A mapping function to call on every element of the array.
89     * @param thisArg Value of 'this' used to invoke the mapfn.
90     */
91    from<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
92}
93
94interface ReadonlyArray<T> {
95    /** Iterator of values in the array. */
96    [Symbol.iterator](): IterableIterator<T>;
97
98    /**
99     * Returns an iterable of key, value pairs for every entry in the array
100     */
101    entries(): IterableIterator<[number, T]>;
102
103    /**
104     * Returns an iterable of keys in the array
105     */
106    keys(): IterableIterator<number>;
107
108    /**
109     * Returns an iterable of values in the array
110     */
111    values(): IterableIterator<T>;
112}
113
114interface IArguments {
115    /** Iterator */
116    [Symbol.iterator](): IterableIterator<any>;
117}
118
119interface Map<K, V> {
120    /** Returns an iterable of entries in the map. */
121    [Symbol.iterator](): IterableIterator<[K, V]>;
122
123    /**
124     * Returns an iterable of key, value pairs for every entry in the map.
125     */
126    entries(): IterableIterator<[K, V]>;
127
128    /**
129     * Returns an iterable of keys in the map
130     */
131    keys(): IterableIterator<K>;
132
133    /**
134     * Returns an iterable of values in the map
135     */
136    values(): IterableIterator<V>;
137}
138
139interface ReadonlyMap<K, V> {
140    /** Returns an iterable of entries in the map. */
141    [Symbol.iterator](): IterableIterator<[K, V]>;
142
143    /**
144     * Returns an iterable of key, value pairs for every entry in the map.
145     */
146    entries(): IterableIterator<[K, V]>;
147
148    /**
149     * Returns an iterable of keys in the map
150     */
151    keys(): IterableIterator<K>;
152
153    /**
154     * Returns an iterable of values in the map
155     */
156    values(): IterableIterator<V>;
157}
158
159interface MapConstructor {
160    new <K, V>(iterable: Iterable<readonly [K, V]>): Map<K, V>;
161}
162
163interface WeakMap<K extends object, V> { }
164
165interface WeakMapConstructor {
166    new <K extends object, V>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
167}
168
169interface Set<T> {
170    /** Iterates over values in the set. */
171    [Symbol.iterator](): IterableIterator<T>;
172    /**
173     * Returns an iterable of [v,v] pairs for every value `v` in the set.
174     */
175    entries(): IterableIterator<[T, T]>;
176    /**
177     * Despite its name, returns an iterable of the values in the set,
178     */
179    keys(): IterableIterator<T>;
180
181    /**
182     * Returns an iterable of values in the set.
183     */
184    values(): IterableIterator<T>;
185}
186
187interface ReadonlySet<T> {
188    /** Iterates over values in the set. */
189    [Symbol.iterator](): IterableIterator<T>;
190
191    /**
192     * Returns an iterable of [v,v] pairs for every value `v` in the set.
193     */
194    entries(): IterableIterator<[T, T]>;
195
196    /**
197     * Despite its name, returns an iterable of the values in the set,
198     */
199    keys(): IterableIterator<T>;
200
201    /**
202     * Returns an iterable of values in the set.
203     */
204    values(): IterableIterator<T>;
205}
206
207interface SetConstructor {
208    new <T>(iterable?: Iterable<T> | null): Set<T>;
209}
210
211interface WeakSet<T extends object> { }
212
213interface WeakSetConstructor {
214    new <T extends object = object>(iterable: Iterable<T>): WeakSet<T>;
215}
216
217interface Promise<T> { }
218
219interface PromiseConstructor {
220    /**
221     * Creates a Promise that is resolved with an array of results when all of the provided Promises
222     * resolve, or rejected when any Promise is rejected.
223     * @param values An array of Promises.
224     * @returns A new Promise.
225     */
226    all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;
227
228    /**
229     * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
230     * or rejected.
231     * @param values An array of Promises.
232     * @returns A new Promise.
233     */
234    race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
235}
236
237declare namespace Reflect {
238    function enumerate(target: object): IterableIterator<any>;
239}
240
241interface String {
242    /** Iterator */
243    [Symbol.iterator](): IterableIterator<string>;
244}
245
246interface Int8Array {
247    [Symbol.iterator](): IterableIterator<number>;
248    /**
249     * Returns an array of key, value pairs for every entry in the array
250     */
251    entries(): IterableIterator<[number, number]>;
252    /**
253     * Returns an list of keys in the array
254     */
255    keys(): IterableIterator<number>;
256    /**
257     * Returns an list of values in the array
258     */
259    values(): IterableIterator<number>;
260}
261
262interface Int8ArrayConstructor {
263    new (elements: Iterable<number>): Int8Array;
264
265    /**
266     * Creates an array from an array-like or iterable object.
267     * @param arrayLike An array-like or iterable object to convert to an array.
268     * @param mapfn A mapping function to call on every element of the array.
269     * @param thisArg Value of 'this' used to invoke the mapfn.
270     */
271    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
272}
273
274interface Uint8Array {
275    [Symbol.iterator](): IterableIterator<number>;
276    /**
277     * Returns an array of key, value pairs for every entry in the array
278     */
279    entries(): IterableIterator<[number, number]>;
280    /**
281     * Returns an list of keys in the array
282     */
283    keys(): IterableIterator<number>;
284    /**
285     * Returns an list of values in the array
286     */
287    values(): IterableIterator<number>;
288}
289
290interface Uint8ArrayConstructor {
291    new (elements: Iterable<number>): Uint8Array;
292
293    /**
294     * Creates an array from an array-like or iterable object.
295     * @param arrayLike An array-like or iterable object to convert to an array.
296     * @param mapfn A mapping function to call on every element of the array.
297     * @param thisArg Value of 'this' used to invoke the mapfn.
298     */
299    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
300}
301
302interface Uint8ClampedArray {
303    [Symbol.iterator](): IterableIterator<number>;
304    /**
305     * Returns an array of key, value pairs for every entry in the array
306     */
307    entries(): IterableIterator<[number, number]>;
308
309    /**
310     * Returns an list of keys in the array
311     */
312    keys(): IterableIterator<number>;
313
314    /**
315     * Returns an list of values in the array
316     */
317    values(): IterableIterator<number>;
318}
319
320interface Uint8ClampedArrayConstructor {
321    new (elements: Iterable<number>): Uint8ClampedArray;
322
323
324    /**
325     * Creates an array from an array-like or iterable object.
326     * @param arrayLike An array-like or iterable object to convert to an array.
327     * @param mapfn A mapping function to call on every element of the array.
328     * @param thisArg Value of 'this' used to invoke the mapfn.
329     */
330    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
331}
332
333interface Int16Array {
334    [Symbol.iterator](): IterableIterator<number>;
335    /**
336     * Returns an array of key, value pairs for every entry in the array
337     */
338    entries(): IterableIterator<[number, number]>;
339
340    /**
341     * Returns an list of keys in the array
342     */
343    keys(): IterableIterator<number>;
344
345    /**
346     * Returns an list of values in the array
347     */
348    values(): IterableIterator<number>;
349}
350
351interface Int16ArrayConstructor {
352    new (elements: Iterable<number>): Int16Array;
353
354    /**
355     * Creates an array from an array-like or iterable object.
356     * @param arrayLike An array-like or iterable object to convert to an array.
357     * @param mapfn A mapping function to call on every element of the array.
358     * @param thisArg Value of 'this' used to invoke the mapfn.
359     */
360    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
361}
362
363interface Uint16Array {
364    [Symbol.iterator](): IterableIterator<number>;
365    /**
366     * Returns an array of key, value pairs for every entry in the array
367     */
368    entries(): IterableIterator<[number, number]>;
369    /**
370     * Returns an list of keys in the array
371     */
372    keys(): IterableIterator<number>;
373    /**
374     * Returns an list of values in the array
375     */
376    values(): IterableIterator<number>;
377}
378
379interface Uint16ArrayConstructor {
380    new (elements: Iterable<number>): Uint16Array;
381
382    /**
383     * Creates an array from an array-like or iterable object.
384     * @param arrayLike An array-like or iterable object to convert to an array.
385     * @param mapfn A mapping function to call on every element of the array.
386     * @param thisArg Value of 'this' used to invoke the mapfn.
387     */
388    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
389}
390
391interface Int32Array {
392    [Symbol.iterator](): IterableIterator<number>;
393    /**
394     * Returns an array of key, value pairs for every entry in the array
395     */
396    entries(): IterableIterator<[number, number]>;
397    /**
398     * Returns an list of keys in the array
399     */
400    keys(): IterableIterator<number>;
401    /**
402     * Returns an list of values in the array
403     */
404    values(): IterableIterator<number>;
405}
406
407interface Int32ArrayConstructor {
408    new (elements: Iterable<number>): Int32Array;
409
410    /**
411     * Creates an array from an array-like or iterable object.
412     * @param arrayLike An array-like or iterable object to convert to an array.
413     * @param mapfn A mapping function to call on every element of the array.
414     * @param thisArg Value of 'this' used to invoke the mapfn.
415     */
416    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
417}
418
419interface Uint32Array {
420    [Symbol.iterator](): IterableIterator<number>;
421    /**
422     * Returns an array of key, value pairs for every entry in the array
423     */
424    entries(): IterableIterator<[number, number]>;
425    /**
426     * Returns an list of keys in the array
427     */
428    keys(): IterableIterator<number>;
429    /**
430     * Returns an list of values in the array
431     */
432    values(): IterableIterator<number>;
433}
434
435interface Uint32ArrayConstructor {
436    new (elements: Iterable<number>): Uint32Array;
437
438    /**
439     * Creates an array from an array-like or iterable object.
440     * @param arrayLike An array-like or iterable object to convert to an array.
441     * @param mapfn A mapping function to call on every element of the array.
442     * @param thisArg Value of 'this' used to invoke the mapfn.
443     */
444    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
445}
446
447interface Float32Array {
448    [Symbol.iterator](): IterableIterator<number>;
449    /**
450     * Returns an array of key, value pairs for every entry in the array
451     */
452    entries(): IterableIterator<[number, number]>;
453    /**
454     * Returns an list of keys in the array
455     */
456    keys(): IterableIterator<number>;
457    /**
458     * Returns an list of values in the array
459     */
460    values(): IterableIterator<number>;
461}
462
463interface Float32ArrayConstructor {
464    new (elements: Iterable<number>): Float32Array;
465
466    /**
467     * Creates an array from an array-like or iterable object.
468     * @param arrayLike An array-like or iterable object to convert to an array.
469     * @param mapfn A mapping function to call on every element of the array.
470     * @param thisArg Value of 'this' used to invoke the mapfn.
471     */
472    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
473}
474
475interface Float64Array {
476    [Symbol.iterator](): IterableIterator<number>;
477    /**
478     * Returns an array of key, value pairs for every entry in the array
479     */
480    entries(): IterableIterator<[number, number]>;
481    /**
482     * Returns an list of keys in the array
483     */
484    keys(): IterableIterator<number>;
485    /**
486     * Returns an list of values in the array
487     */
488    values(): IterableIterator<number>;
489}
490
491interface Float64ArrayConstructor {
492    new (elements: Iterable<number>): Float64Array;
493
494    /**
495     * Creates an array from an array-like or iterable object.
496     * @param arrayLike An array-like or iterable object to convert to an array.
497     * @param mapfn A mapping function to call on every element of the array.
498     * @param thisArg Value of 'this' used to invoke the mapfn.
499     */
500    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
501}
502