lib.es2015.iterable.d.ts 15 KB

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