UNPKG

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