lib.es2015.iterable.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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(): Map<any, any>;
  127. new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
  128. }
  129. interface WeakMap<K extends object, V> { }
  130. interface WeakMapConstructor {
  131. new <K extends object, V>(iterable: Iterable<readonly [K, V]>): WeakMap<K, V>;
  132. }
  133. interface Set<T> {
  134. /** Iterates over values in the set. */
  135. [Symbol.iterator](): IterableIterator<T>;
  136. /**
  137. * Returns an iterable of [v,v] pairs for every value `v` in the set.
  138. */
  139. entries(): IterableIterator<[T, T]>;
  140. /**
  141. * Despite its name, returns an iterable of the values in the set.
  142. */
  143. keys(): IterableIterator<T>;
  144. /**
  145. * Returns an iterable of values in the set.
  146. */
  147. values(): IterableIterator<T>;
  148. }
  149. interface ReadonlySet<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. * Returns an iterable of values in the set.
  162. */
  163. values(): IterableIterator<T>;
  164. }
  165. interface SetConstructor {
  166. new <T>(iterable?: Iterable<T> | null): Set<T>;
  167. }
  168. interface WeakSet<T extends object> { }
  169. interface WeakSetConstructor {
  170. new <T extends object = object>(iterable: Iterable<T>): WeakSet<T>;
  171. }
  172. interface Promise<T> { }
  173. interface PromiseConstructor {
  174. /**
  175. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  176. * resolve, or rejected when any Promise is rejected.
  177. * @param values An iterable of Promises.
  178. * @returns A new Promise.
  179. */
  180. all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
  181. /**
  182. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  183. * or rejected.
  184. * @param values An iterable of Promises.
  185. * @returns A new Promise.
  186. */
  187. race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
  188. }
  189. interface String {
  190. /** Iterator */
  191. [Symbol.iterator](): IterableIterator<string>;
  192. }
  193. interface Int8Array {
  194. [Symbol.iterator](): IterableIterator<number>;
  195. /**
  196. * Returns an array of key, value pairs for every entry in the array
  197. */
  198. entries(): IterableIterator<[number, number]>;
  199. /**
  200. * Returns an list of keys in the array
  201. */
  202. keys(): IterableIterator<number>;
  203. /**
  204. * Returns an list of values in the array
  205. */
  206. values(): IterableIterator<number>;
  207. }
  208. interface Int8ArrayConstructor {
  209. new (elements: Iterable<number>): Int8Array;
  210. /**
  211. * Creates an array from an array-like or iterable object.
  212. * @param arrayLike An array-like or iterable object to convert to an array.
  213. * @param mapfn A mapping function to call on every element of the array.
  214. * @param thisArg Value of 'this' used to invoke the mapfn.
  215. */
  216. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
  217. }
  218. interface Uint8Array {
  219. [Symbol.iterator](): IterableIterator<number>;
  220. /**
  221. * Returns an array of key, value pairs for every entry in the array
  222. */
  223. entries(): IterableIterator<[number, number]>;
  224. /**
  225. * Returns an list of keys in the array
  226. */
  227. keys(): IterableIterator<number>;
  228. /**
  229. * Returns an list of values in the array
  230. */
  231. values(): IterableIterator<number>;
  232. }
  233. interface Uint8ArrayConstructor {
  234. new (elements: Iterable<number>): Uint8Array;
  235. /**
  236. * Creates an array from an array-like or iterable object.
  237. * @param arrayLike An array-like or iterable object to convert to an array.
  238. * @param mapfn A mapping function to call on every element of the array.
  239. * @param thisArg Value of 'this' used to invoke the mapfn.
  240. */
  241. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
  242. }
  243. interface Uint8ClampedArray {
  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. interface Uint8ClampedArrayConstructor {
  259. new (elements: Iterable<number>): Uint8ClampedArray;
  260. /**
  261. * Creates an array from an array-like or iterable object.
  262. * @param arrayLike An array-like or iterable object to convert to an array.
  263. * @param mapfn A mapping function to call on every element of the array.
  264. * @param thisArg Value of 'this' used to invoke the mapfn.
  265. */
  266. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
  267. }
  268. interface Int16Array {
  269. [Symbol.iterator](): IterableIterator<number>;
  270. /**
  271. * Returns an array of key, value pairs for every entry in the array
  272. */
  273. entries(): IterableIterator<[number, number]>;
  274. /**
  275. * Returns an list of keys in the array
  276. */
  277. keys(): IterableIterator<number>;
  278. /**
  279. * Returns an list of values in the array
  280. */
  281. values(): IterableIterator<number>;
  282. }
  283. interface Int16ArrayConstructor {
  284. new (elements: Iterable<number>): Int16Array;
  285. /**
  286. * Creates an array from an array-like or iterable object.
  287. * @param arrayLike An array-like or iterable object to convert to an array.
  288. * @param mapfn A mapping function to call on every element of the array.
  289. * @param thisArg Value of 'this' used to invoke the mapfn.
  290. */
  291. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
  292. }
  293. interface Uint16Array {
  294. [Symbol.iterator](): IterableIterator<number>;
  295. /**
  296. * Returns an array of key, value pairs for every entry in the array
  297. */
  298. entries(): IterableIterator<[number, number]>;
  299. /**
  300. * Returns an list of keys in the array
  301. */
  302. keys(): IterableIterator<number>;
  303. /**
  304. * Returns an list of values in the array
  305. */
  306. values(): IterableIterator<number>;
  307. }
  308. interface Uint16ArrayConstructor {
  309. new (elements: Iterable<number>): Uint16Array;
  310. /**
  311. * Creates an array from an array-like or iterable object.
  312. * @param arrayLike An array-like or iterable object to convert to an array.
  313. * @param mapfn A mapping function to call on every element of the array.
  314. * @param thisArg Value of 'this' used to invoke the mapfn.
  315. */
  316. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
  317. }
  318. interface Int32Array {
  319. [Symbol.iterator](): IterableIterator<number>;
  320. /**
  321. * Returns an array of key, value pairs for every entry in the array
  322. */
  323. entries(): IterableIterator<[number, number]>;
  324. /**
  325. * Returns an list of keys in the array
  326. */
  327. keys(): IterableIterator<number>;
  328. /**
  329. * Returns an list of values in the array
  330. */
  331. values(): IterableIterator<number>;
  332. }
  333. interface Int32ArrayConstructor {
  334. new (elements: Iterable<number>): Int32Array;
  335. /**
  336. * Creates an array from an array-like or iterable object.
  337. * @param arrayLike An array-like or iterable object to convert to an array.
  338. * @param mapfn A mapping function to call on every element of the array.
  339. * @param thisArg Value of 'this' used to invoke the mapfn.
  340. */
  341. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
  342. }
  343. interface Uint32Array {
  344. [Symbol.iterator](): IterableIterator<number>;
  345. /**
  346. * Returns an array of key, value pairs for every entry in the array
  347. */
  348. entries(): IterableIterator<[number, number]>;
  349. /**
  350. * Returns an list of keys in the array
  351. */
  352. keys(): IterableIterator<number>;
  353. /**
  354. * Returns an list of values in the array
  355. */
  356. values(): IterableIterator<number>;
  357. }
  358. interface Uint32ArrayConstructor {
  359. new (elements: Iterable<number>): Uint32Array;
  360. /**
  361. * Creates an array from an array-like or iterable object.
  362. * @param arrayLike An array-like or iterable object to convert to an array.
  363. * @param mapfn A mapping function to call on every element of the array.
  364. * @param thisArg Value of 'this' used to invoke the mapfn.
  365. */
  366. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
  367. }
  368. interface Float32Array {
  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. interface Float32ArrayConstructor {
  384. new (elements: Iterable<number>): Float32Array;
  385. /**
  386. * Creates an array from an array-like or iterable object.
  387. * @param arrayLike An array-like or iterable object to convert to an array.
  388. * @param mapfn A mapping function to call on every element of the array.
  389. * @param thisArg Value of 'this' used to invoke the mapfn.
  390. */
  391. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
  392. }
  393. interface Float64Array {
  394. [Symbol.iterator](): IterableIterator<number>;
  395. /**
  396. * Returns an array of key, value pairs for every entry in the array
  397. */
  398. entries(): IterableIterator<[number, number]>;
  399. /**
  400. * Returns an list of keys in the array
  401. */
  402. keys(): IterableIterator<number>;
  403. /**
  404. * Returns an list of values in the array
  405. */
  406. values(): IterableIterator<number>;
  407. }
  408. interface Float64ArrayConstructor {
  409. new (elements: Iterable<number>): Float64Array;
  410. /**
  411. * Creates an array from an array-like or iterable object.
  412. * @param arrayLike An array-like or iterable object to convert to an array.
  413. * @param mapfn A mapping function to call on every element of the array.
  414. * @param thisArg Value of 'this' used to invoke the mapfn.
  415. */
  416. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
  417. }