• 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: unique 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(): Map<any, any>;
141    new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
142}
143
144interface WeakMap<K extends object, V> { }
145
146interface WeakMapConstructor {
147    new <K extends object, V>(iterable: Iterable<readonly [K, V]>): WeakMap<K, V>;
148}
149
150interface Set<T> {
151    /** Iterates over values in the set. */
152    [Symbol.iterator](): IterableIterator<T>;
153    /**
154     * Returns an iterable of [v,v] pairs for every value `v` in the set.
155     */
156    entries(): IterableIterator<[T, T]>;
157    /**
158     * Despite its name, returns an iterable of the values in the set.
159     */
160    keys(): IterableIterator<T>;
161
162    /**
163     * Returns an iterable of values in the set.
164     */
165    values(): IterableIterator<T>;
166}
167
168interface ReadonlySet<T> {
169    /** Iterates over values in the set. */
170    [Symbol.iterator](): IterableIterator<T>;
171
172    /**
173     * Returns an iterable of [v,v] pairs for every value `v` in the set.
174     */
175    entries(): IterableIterator<[T, T]>;
176
177    /**
178     * Despite its name, returns an iterable of the values in the set.
179     */
180    keys(): IterableIterator<T>;
181
182    /**
183     * Returns an iterable of values in the set.
184     */
185    values(): IterableIterator<T>;
186}
187
188interface SetConstructor {
189    new <T>(iterable?: Iterable<T> | null): Set<T>;
190}
191
192interface WeakSet<T extends object> { }
193
194interface WeakSetConstructor {
195    new <T extends object = object>(iterable: Iterable<T>): WeakSet<T>;
196}
197
198interface Promise<T> { }
199
200interface PromiseConstructor {
201    /**
202     * Creates a Promise that is resolved with an array of results when all of the provided Promises
203     * resolve, or rejected when any Promise is rejected.
204     * @param values An iterable of Promises.
205     * @returns A new Promise.
206     */
207    all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
208
209    /**
210     * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
211     * or rejected.
212     * @param values An iterable of Promises.
213     * @returns A new Promise.
214     */
215    race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
216}
217
218interface String {
219    /** Iterator */
220    [Symbol.iterator](): IterableIterator<string>;
221}
222
223interface Int8Array {
224    [Symbol.iterator](): IterableIterator<number>;
225    /**
226     * Returns an array of key, value pairs for every entry in the array
227     */
228    entries(): IterableIterator<[number, number]>;
229    /**
230     * Returns an list of keys in the array
231     */
232    keys(): IterableIterator<number>;
233    /**
234     * Returns an list of values in the array
235     */
236    values(): IterableIterator<number>;
237}
238
239interface Int8ArrayConstructor {
240    new (elements: Iterable<number>): Int8Array;
241
242    /**
243     * Creates an array from an array-like or iterable object.
244     * @param arrayLike An array-like or iterable object to convert to an array.
245     * @param mapfn A mapping function to call on every element of the array.
246     * @param thisArg Value of 'this' used to invoke the mapfn.
247     */
248    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
249}
250
251interface Uint8Array {
252    [Symbol.iterator](): IterableIterator<number>;
253    /**
254     * Returns an array of key, value pairs for every entry in the array
255     */
256    entries(): IterableIterator<[number, number]>;
257    /**
258     * Returns an list of keys in the array
259     */
260    keys(): IterableIterator<number>;
261    /**
262     * Returns an list of values in the array
263     */
264    values(): IterableIterator<number>;
265}
266
267interface Uint8ArrayConstructor {
268    new (elements: Iterable<number>): Uint8Array;
269
270    /**
271     * Creates an array from an array-like or iterable object.
272     * @param arrayLike An array-like or iterable object to convert to an array.
273     * @param mapfn A mapping function to call on every element of the array.
274     * @param thisArg Value of 'this' used to invoke the mapfn.
275     */
276    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
277}
278
279interface Uint8ClampedArray {
280    [Symbol.iterator](): IterableIterator<number>;
281    /**
282     * Returns an array of key, value pairs for every entry in the array
283     */
284    entries(): IterableIterator<[number, number]>;
285
286    /**
287     * Returns an list of keys in the array
288     */
289    keys(): IterableIterator<number>;
290
291    /**
292     * Returns an list of values in the array
293     */
294    values(): IterableIterator<number>;
295}
296
297interface Uint8ClampedArrayConstructor {
298    new (elements: Iterable<number>): Uint8ClampedArray;
299
300
301    /**
302     * Creates an array from an array-like or iterable object.
303     * @param arrayLike An array-like or iterable object to convert to an array.
304     * @param mapfn A mapping function to call on every element of the array.
305     * @param thisArg Value of 'this' used to invoke the mapfn.
306     */
307    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
308}
309
310interface Int16Array {
311    [Symbol.iterator](): IterableIterator<number>;
312    /**
313     * Returns an array of key, value pairs for every entry in the array
314     */
315    entries(): IterableIterator<[number, number]>;
316
317    /**
318     * Returns an list of keys in the array
319     */
320    keys(): IterableIterator<number>;
321
322    /**
323     * Returns an list of values in the array
324     */
325    values(): IterableIterator<number>;
326}
327
328interface Int16ArrayConstructor {
329    new (elements: Iterable<number>): Int16Array;
330
331    /**
332     * Creates an array from an array-like or iterable object.
333     * @param arrayLike An array-like or iterable object to convert to an array.
334     * @param mapfn A mapping function to call on every element of the array.
335     * @param thisArg Value of 'this' used to invoke the mapfn.
336     */
337    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
338}
339
340interface Uint16Array {
341    [Symbol.iterator](): IterableIterator<number>;
342    /**
343     * Returns an array of key, value pairs for every entry in the array
344     */
345    entries(): IterableIterator<[number, number]>;
346    /**
347     * Returns an list of keys in the array
348     */
349    keys(): IterableIterator<number>;
350    /**
351     * Returns an list of values in the array
352     */
353    values(): IterableIterator<number>;
354}
355
356interface Uint16ArrayConstructor {
357    new (elements: Iterable<number>): Uint16Array;
358
359    /**
360     * Creates an array from an array-like or iterable object.
361     * @param arrayLike An array-like or iterable object to convert to an array.
362     * @param mapfn A mapping function to call on every element of the array.
363     * @param thisArg Value of 'this' used to invoke the mapfn.
364     */
365    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
366}
367
368interface Int32Array {
369    [Symbol.iterator](): IterableIterator<number>;
370    /**
371     * Returns an array of key, value pairs for every entry in the array
372     */
373    entries(): IterableIterator<[number, number]>;
374    /**
375     * Returns an list of keys in the array
376     */
377    keys(): IterableIterator<number>;
378    /**
379     * Returns an list of values in the array
380     */
381    values(): IterableIterator<number>;
382}
383
384interface Int32ArrayConstructor {
385    new (elements: Iterable<number>): Int32Array;
386
387    /**
388     * Creates an array from an array-like or iterable object.
389     * @param arrayLike An array-like or iterable object to convert to an array.
390     * @param mapfn A mapping function to call on every element of the array.
391     * @param thisArg Value of 'this' used to invoke the mapfn.
392     */
393    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
394}
395
396interface Uint32Array {
397    [Symbol.iterator](): IterableIterator<number>;
398    /**
399     * Returns an array of key, value pairs for every entry in the array
400     */
401    entries(): IterableIterator<[number, number]>;
402    /**
403     * Returns an list of keys in the array
404     */
405    keys(): IterableIterator<number>;
406    /**
407     * Returns an list of values in the array
408     */
409    values(): IterableIterator<number>;
410}
411
412interface Uint32ArrayConstructor {
413    new (elements: Iterable<number>): Uint32Array;
414
415    /**
416     * Creates an array from an array-like or iterable object.
417     * @param arrayLike An array-like or iterable object to convert to an array.
418     * @param mapfn A mapping function to call on every element of the array.
419     * @param thisArg Value of 'this' used to invoke the mapfn.
420     */
421    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
422}
423
424interface Float32Array {
425    [Symbol.iterator](): IterableIterator<number>;
426    /**
427     * Returns an array of key, value pairs for every entry in the array
428     */
429    entries(): IterableIterator<[number, number]>;
430    /**
431     * Returns an list of keys in the array
432     */
433    keys(): IterableIterator<number>;
434    /**
435     * Returns an list of values in the array
436     */
437    values(): IterableIterator<number>;
438}
439
440interface Float32ArrayConstructor {
441    new (elements: Iterable<number>): Float32Array;
442
443    /**
444     * Creates an array from an array-like or iterable object.
445     * @param arrayLike An array-like or iterable object to convert to an array.
446     * @param mapfn A mapping function to call on every element of the array.
447     * @param thisArg Value of 'this' used to invoke the mapfn.
448     */
449    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
450}
451
452interface Float64Array {
453    [Symbol.iterator](): IterableIterator<number>;
454    /**
455     * Returns an array of key, value pairs for every entry in the array
456     */
457    entries(): IterableIterator<[number, number]>;
458    /**
459     * Returns an list of keys in the array
460     */
461    keys(): IterableIterator<number>;
462    /**
463     * Returns an list of values in the array
464     */
465    values(): IterableIterator<number>;
466}
467
468interface Float64ArrayConstructor {
469    new (elements: Iterable<number>): Float64Array;
470
471    /**
472     * Creates an array from an array-like or iterable object.
473     * @param arrayLike An array-like or iterable object to convert to an array.
474     * @param mapfn A mapping function to call on every element of the array.
475     * @param thisArg Value of 'this' used to invoke the mapfn.
476     */
477    from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
478}
479