UNPKG

15.7 kBTypeScriptView Raw
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 iterable of Promises.
224 * @returns A new Promise.
225 */
226 all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
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 iterable of Promises.
232 * @returns A new Promise.
233 */
234 race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;
235
236 /**
237 * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
238 * or rejected.
239 * @param values An iterable of Promises.
240 * @returns A new Promise.
241 */
242 race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
243}
244
245declare namespace Reflect {
246 function enumerate(target: object): IterableIterator<any>;
247}
248
249interface String {
250 /** Iterator */
251 [Symbol.iterator](): IterableIterator<string>;
252}
253
254interface Int8Array {
255 [Symbol.iterator](): IterableIterator<number>;
256 /**
257 * Returns an array of key, value pairs for every entry in the array
258 */
259 entries(): IterableIterator<[number, number]>;
260 /**
261 * Returns an list of keys in the array
262 */
263 keys(): IterableIterator<number>;
264 /**
265 * Returns an list of values in the array
266 */
267 values(): IterableIterator<number>;
268}
269
270interface Int8ArrayConstructor {
271 new (elements: Iterable<number>): Int8Array;
272
273 /**
274 * Creates an array from an array-like or iterable object.
275 * @param arrayLike An array-like or iterable object to convert to an array.
276 * @param mapfn A mapping function to call on every element of the array.
277 * @param thisArg Value of 'this' used to invoke the mapfn.
278 */
279 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
280}
281
282interface Uint8Array {
283 [Symbol.iterator](): IterableIterator<number>;
284 /**
285 * Returns an array of key, value pairs for every entry in the array
286 */
287 entries(): IterableIterator<[number, number]>;
288 /**
289 * Returns an list of keys in the array
290 */
291 keys(): IterableIterator<number>;
292 /**
293 * Returns an list of values in the array
294 */
295 values(): IterableIterator<number>;
296}
297
298interface Uint8ArrayConstructor {
299 new (elements: Iterable<number>): Uint8Array;
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): Uint8Array;
308}
309
310interface Uint8ClampedArray {
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 Uint8ClampedArrayConstructor {
329 new (elements: Iterable<number>): Uint8ClampedArray;
330
331
332 /**
333 * Creates an array from an array-like or iterable object.
334 * @param arrayLike An array-like or iterable object to convert to an array.
335 * @param mapfn A mapping function to call on every element of the array.
336 * @param thisArg Value of 'this' used to invoke the mapfn.
337 */
338 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
339}
340
341interface Int16Array {
342 [Symbol.iterator](): IterableIterator<number>;
343 /**
344 * Returns an array of key, value pairs for every entry in the array
345 */
346 entries(): IterableIterator<[number, number]>;
347
348 /**
349 * Returns an list of keys in the array
350 */
351 keys(): IterableIterator<number>;
352
353 /**
354 * Returns an list of values in the array
355 */
356 values(): IterableIterator<number>;
357}
358
359interface Int16ArrayConstructor {
360 new (elements: Iterable<number>): Int16Array;
361
362 /**
363 * Creates an array from an array-like or iterable object.
364 * @param arrayLike An array-like or iterable object to convert to an array.
365 * @param mapfn A mapping function to call on every element of the array.
366 * @param thisArg Value of 'this' used to invoke the mapfn.
367 */
368 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
369}
370
371interface Uint16Array {
372 [Symbol.iterator](): IterableIterator<number>;
373 /**
374 * Returns an array of key, value pairs for every entry in the array
375 */
376 entries(): IterableIterator<[number, number]>;
377 /**
378 * Returns an list of keys in the array
379 */
380 keys(): IterableIterator<number>;
381 /**
382 * Returns an list of values in the array
383 */
384 values(): IterableIterator<number>;
385}
386
387interface Uint16ArrayConstructor {
388 new (elements: Iterable<number>): Uint16Array;
389
390 /**
391 * Creates an array from an array-like or iterable object.
392 * @param arrayLike An array-like or iterable object to convert to an array.
393 * @param mapfn A mapping function to call on every element of the array.
394 * @param thisArg Value of 'this' used to invoke the mapfn.
395 */
396 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
397}
398
399interface Int32Array {
400 [Symbol.iterator](): IterableIterator<number>;
401 /**
402 * Returns an array of key, value pairs for every entry in the array
403 */
404 entries(): IterableIterator<[number, number]>;
405 /**
406 * Returns an list of keys in the array
407 */
408 keys(): IterableIterator<number>;
409 /**
410 * Returns an list of values in the array
411 */
412 values(): IterableIterator<number>;
413}
414
415interface Int32ArrayConstructor {
416 new (elements: Iterable<number>): Int32Array;
417
418 /**
419 * Creates an array from an array-like or iterable object.
420 * @param arrayLike An array-like or iterable object to convert to an array.
421 * @param mapfn A mapping function to call on every element of the array.
422 * @param thisArg Value of 'this' used to invoke the mapfn.
423 */
424 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
425}
426
427interface Uint32Array {
428 [Symbol.iterator](): IterableIterator<number>;
429 /**
430 * Returns an array of key, value pairs for every entry in the array
431 */
432 entries(): IterableIterator<[number, number]>;
433 /**
434 * Returns an list of keys in the array
435 */
436 keys(): IterableIterator<number>;
437 /**
438 * Returns an list of values in the array
439 */
440 values(): IterableIterator<number>;
441}
442
443interface Uint32ArrayConstructor {
444 new (elements: Iterable<number>): Uint32Array;
445
446 /**
447 * Creates an array from an array-like or iterable object.
448 * @param arrayLike An array-like or iterable object to convert to an array.
449 * @param mapfn A mapping function to call on every element of the array.
450 * @param thisArg Value of 'this' used to invoke the mapfn.
451 */
452 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
453}
454
455interface Float32Array {
456 [Symbol.iterator](): IterableIterator<number>;
457 /**
458 * Returns an array of key, value pairs for every entry in the array
459 */
460 entries(): IterableIterator<[number, number]>;
461 /**
462 * Returns an list of keys in the array
463 */
464 keys(): IterableIterator<number>;
465 /**
466 * Returns an list of values in the array
467 */
468 values(): IterableIterator<number>;
469}
470
471interface Float32ArrayConstructor {
472 new (elements: Iterable<number>): Float32Array;
473
474 /**
475 * Creates an array from an array-like or iterable object.
476 * @param arrayLike An array-like or iterable object to convert to an array.
477 * @param mapfn A mapping function to call on every element of the array.
478 * @param thisArg Value of 'this' used to invoke the mapfn.
479 */
480 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
481}
482
483interface Float64Array {
484 [Symbol.iterator](): IterableIterator<number>;
485 /**
486 * Returns an array of key, value pairs for every entry in the array
487 */
488 entries(): IterableIterator<[number, number]>;
489 /**
490 * Returns an list of keys in the array
491 */
492 keys(): IterableIterator<number>;
493 /**
494 * Returns an list of values in the array
495 */
496 values(): IterableIterator<number>;
497}
498
499interface Float64ArrayConstructor {
500 new (elements: Iterable<number>): Float64Array;
501
502 /**
503 * Creates an array from an array-like or iterable object.
504 * @param arrayLike An array-like or iterable object to convert to an array.
505 * @param mapfn A mapping function to call on every element of the array.
506 * @param thisArg Value of 'this' used to invoke the mapfn.
507 */
508 from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
509}
510
\No newline at end of file