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