/lib/lib.es2015.iterable.d.ts

https://gitlab.com/nalinrajgupta/nalin · TypeScript Typings · 441 lines · 158 code · 58 blank · 225 comment · 2 complexity · 36d97c9f22cc3c49bf740daaa37368bd MD5 · raw file

  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 path="lib.es2015.symbol.d.ts" />
  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: symbol;
  21. }
  22. interface IteratorResult<T> {
  23. done: boolean;
  24. value: T;
  25. }
  26. interface Iterator<T> {
  27. next(value?: any): IteratorResult<T>;
  28. return?(value?: any): IteratorResult<T>;
  29. throw?(e?: any): IteratorResult<T>;
  30. }
  31. interface Iterable<T> {
  32. [Symbol.iterator](): Iterator<T>;
  33. }
  34. interface IterableIterator<T> extends Iterator<T> {
  35. [Symbol.iterator](): IterableIterator<T>;
  36. }
  37. interface Array<T> {
  38. /** Iterator */
  39. [Symbol.iterator](): IterableIterator<T>;
  40. /**
  41. * Returns an array of key, value pairs for every entry in the array
  42. */
  43. entries(): IterableIterator<[number, T]>;
  44. /**
  45. * Returns an list of keys in the array
  46. */
  47. keys(): IterableIterator<number>;
  48. /**
  49. * Returns an list of values in the array
  50. */
  51. values(): IterableIterator<T>;
  52. }
  53. interface ArrayConstructor {
  54. /**
  55. * Creates an array from an iterable object.
  56. * @param iterable An iterable object to convert to an array.
  57. * @param mapfn A mapping function to call on every element of the array.
  58. * @param thisArg Value of 'this' used to invoke the mapfn.
  59. */
  60. from<T, U>(iterable: Iterable<T>, mapfn: (v: T, k: number) => U, thisArg?: any): Array<U>;
  61. /**
  62. * Creates an array from an iterable object.
  63. * @param iterable An iterable object to convert to an array.
  64. */
  65. from<T>(iterable: Iterable<T>): Array<T>;
  66. }
  67. interface IArguments {
  68. /** Iterator */
  69. [Symbol.iterator](): IterableIterator<any>;
  70. }
  71. interface Map<K, V> {
  72. [Symbol.iterator](): IterableIterator<[K,V]>;
  73. entries(): IterableIterator<[K, V]>;
  74. keys(): IterableIterator<K>;
  75. values(): IterableIterator<V>;
  76. }
  77. interface MapConstructor {
  78. new <K, V>(iterable: Iterable<[K, V]>): Map<K, V>;
  79. }
  80. interface WeakMap<K, V> { }
  81. interface WeakMapConstructor {
  82. new <K, V>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
  83. }
  84. interface Set<T> {
  85. [Symbol.iterator](): IterableIterator<T>;
  86. entries(): IterableIterator<[T, T]>;
  87. keys(): IterableIterator<T>;
  88. values(): IterableIterator<T>;
  89. }
  90. interface SetConstructor {
  91. new <T>(iterable: Iterable<T>): Set<T>;
  92. }
  93. interface WeakSet<T> { }
  94. interface WeakSetConstructor {
  95. new <T>(iterable: Iterable<T>): WeakSet<T>;
  96. }
  97. interface Promise<T> { }
  98. interface PromiseConstructor {
  99. /**
  100. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  101. * resolve, or rejected when any Promise is rejected.
  102. * @param values An array of Promises.
  103. * @returns A new Promise.
  104. */
  105. all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;
  106. /**
  107. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  108. * or rejected.
  109. * @param values An array of Promises.
  110. * @returns A new Promise.
  111. */
  112. race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
  113. }
  114. declare namespace Reflect {
  115. function enumerate(target: any): IterableIterator<any>;
  116. }
  117. interface String {
  118. /** Iterator */
  119. [Symbol.iterator](): IterableIterator<string>;
  120. }
  121. /**
  122. * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested
  123. * number of bytes could not be allocated an exception is raised.
  124. */
  125. interface Int8Array {
  126. [Symbol.iterator](): IterableIterator<number>;
  127. /**
  128. * Returns an array of key, value pairs for every entry in the array
  129. */
  130. entries(): IterableIterator<[number, number]>;
  131. /**
  132. * Returns an list of keys in the array
  133. */
  134. keys(): IterableIterator<number>;
  135. /**
  136. * Returns an list of values in the array
  137. */
  138. values(): IterableIterator<number>;
  139. }
  140. interface Int8ArrayConstructor {
  141. new (elements: Iterable<number>): Int8Array;
  142. /**
  143. * Creates an array from an array-like or iterable object.
  144. * @param arrayLike An array-like or iterable object to convert to an array.
  145. * @param mapfn A mapping function to call on every element of the array.
  146. * @param thisArg Value of 'this' used to invoke the mapfn.
  147. */
  148. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
  149. }
  150. /**
  151. * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
  152. * requested number of bytes could not be allocated an exception is raised.
  153. */
  154. interface Uint8Array {
  155. [Symbol.iterator](): IterableIterator<number>;
  156. /**
  157. * Returns an array of key, value pairs for every entry in the array
  158. */
  159. entries(): IterableIterator<[number, number]>;
  160. /**
  161. * Returns an list of keys in the array
  162. */
  163. keys(): IterableIterator<number>;
  164. /**
  165. * Returns an list of values in the array
  166. */
  167. values(): IterableIterator<number>;
  168. }
  169. interface Uint8ArrayConstructor {
  170. new (elements: Iterable<number>): Uint8Array;
  171. /**
  172. * Creates an array from an array-like or iterable object.
  173. * @param arrayLike An array-like or iterable object to convert to an array.
  174. * @param mapfn A mapping function to call on every element of the array.
  175. * @param thisArg Value of 'this' used to invoke the mapfn.
  176. */
  177. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
  178. }
  179. /**
  180. * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0.
  181. * If the requested number of bytes could not be allocated an exception is raised.
  182. */
  183. interface Uint8ClampedArray {
  184. [Symbol.iterator](): IterableIterator<number>;
  185. /**
  186. * Returns an array of key, value pairs for every entry in the array
  187. */
  188. entries(): IterableIterator<[number, number]>;
  189. /**
  190. * Returns an list of keys in the array
  191. */
  192. keys(): IterableIterator<number>;
  193. /**
  194. * Returns an list of values in the array
  195. */
  196. values(): IterableIterator<number>;
  197. }
  198. interface Uint8ClampedArrayConstructor {
  199. new (elements: Iterable<number>): Uint8ClampedArray;
  200. /**
  201. * Creates an array from an array-like or iterable object.
  202. * @param arrayLike An array-like or iterable object to convert to an array.
  203. * @param mapfn A mapping function to call on every element of the array.
  204. * @param thisArg Value of 'this' used to invoke the mapfn.
  205. */
  206. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
  207. }
  208. /**
  209. * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the
  210. * requested number of bytes could not be allocated an exception is raised.
  211. */
  212. interface Int16Array {
  213. [Symbol.iterator](): IterableIterator<number>;
  214. /**
  215. * Returns an array of key, value pairs for every entry in the array
  216. */
  217. entries(): IterableIterator<[number, number]>;
  218. /**
  219. * Returns an list of keys in the array
  220. */
  221. keys(): IterableIterator<number>;
  222. /**
  223. * Returns an list of values in the array
  224. */
  225. values(): IterableIterator<number>;
  226. }
  227. interface Int16ArrayConstructor {
  228. new (elements: Iterable<number>): Int16Array;
  229. /**
  230. * Creates an array from an array-like or iterable object.
  231. * @param arrayLike An array-like or iterable object to convert to an array.
  232. * @param mapfn A mapping function to call on every element of the array.
  233. * @param thisArg Value of 'this' used to invoke the mapfn.
  234. */
  235. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
  236. }
  237. /**
  238. * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the
  239. * requested number of bytes could not be allocated an exception is raised.
  240. */
  241. interface Uint16Array {
  242. [Symbol.iterator](): IterableIterator<number>;
  243. /**
  244. * Returns an array of key, value pairs for every entry in the array
  245. */
  246. entries(): IterableIterator<[number, number]>;
  247. /**
  248. * Returns an list of keys in the array
  249. */
  250. keys(): IterableIterator<number>;
  251. /**
  252. * Returns an list of values in the array
  253. */
  254. values(): IterableIterator<number>;
  255. }
  256. interface Uint16ArrayConstructor {
  257. new (elements: Iterable<number>): Uint16Array;
  258. /**
  259. * Creates an array from an array-like or iterable object.
  260. * @param arrayLike An array-like or iterable object to convert to an array.
  261. * @param mapfn A mapping function to call on every element of the array.
  262. * @param thisArg Value of 'this' used to invoke the mapfn.
  263. */
  264. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
  265. }
  266. /**
  267. * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the
  268. * requested number of bytes could not be allocated an exception is raised.
  269. */
  270. interface Int32Array {
  271. [Symbol.iterator](): IterableIterator<number>;
  272. /**
  273. * Returns an array of key, value pairs for every entry in the array
  274. */
  275. entries(): IterableIterator<[number, number]>;
  276. /**
  277. * Returns an list of keys in the array
  278. */
  279. keys(): IterableIterator<number>;
  280. /**
  281. * Returns an list of values in the array
  282. */
  283. values(): IterableIterator<number>;
  284. }
  285. interface Int32ArrayConstructor {
  286. new (elements: Iterable<number>): Int32Array;
  287. /**
  288. * Creates an array from an array-like or iterable object.
  289. * @param arrayLike An array-like or iterable object to convert to an array.
  290. * @param mapfn A mapping function to call on every element of the array.
  291. * @param thisArg Value of 'this' used to invoke the mapfn.
  292. */
  293. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
  294. }
  295. /**
  296. * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the
  297. * requested number of bytes could not be allocated an exception is raised.
  298. */
  299. interface Uint32Array {
  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. * Returns an list of keys in the array
  307. */
  308. keys(): IterableIterator<number>;
  309. /**
  310. * Returns an list of values in the array
  311. */
  312. values(): IterableIterator<number>;
  313. }
  314. interface Uint32ArrayConstructor {
  315. new (elements: Iterable<number>): Uint32Array;
  316. /**
  317. * Creates an array from an array-like or iterable object.
  318. * @param arrayLike An array-like or iterable object to convert to an array.
  319. * @param mapfn A mapping function to call on every element of the array.
  320. * @param thisArg Value of 'this' used to invoke the mapfn.
  321. */
  322. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
  323. }
  324. /**
  325. * A typed array of 32-bit float values. The contents are initialized to 0. If the requested number
  326. * of bytes could not be allocated an exception is raised.
  327. */
  328. interface Float32Array {
  329. [Symbol.iterator](): IterableIterator<number>;
  330. /**
  331. * Returns an array of key, value pairs for every entry in the array
  332. */
  333. entries(): IterableIterator<[number, number]>;
  334. /**
  335. * Returns an list of keys in the array
  336. */
  337. keys(): IterableIterator<number>;
  338. /**
  339. * Returns an list of values in the array
  340. */
  341. values(): IterableIterator<number>;
  342. }
  343. interface Float32ArrayConstructor {
  344. new (elements: Iterable<number>): Float32Array;
  345. /**
  346. * Creates an array from an array-like or iterable object.
  347. * @param arrayLike An array-like or iterable object to convert to an array.
  348. * @param mapfn A mapping function to call on every element of the array.
  349. * @param thisArg Value of 'this' used to invoke the mapfn.
  350. */
  351. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
  352. }
  353. /**
  354. * A typed array of 64-bit float values. The contents are initialized to 0. If the requested
  355. * number of bytes could not be allocated an exception is raised.
  356. */
  357. interface Float64Array {
  358. [Symbol.iterator](): IterableIterator<number>;
  359. /**
  360. * Returns an array of key, value pairs for every entry in the array
  361. */
  362. entries(): IterableIterator<[number, number]>;
  363. /**
  364. * Returns an list of keys in the array
  365. */
  366. keys(): IterableIterator<number>;
  367. /**
  368. * Returns an list of values in the array
  369. */
  370. values(): IterableIterator<number>;
  371. }
  372. interface Float64ArrayConstructor {
  373. new (elements: Iterable<number>): Float64Array;
  374. /**
  375. * Creates an array from an array-like or iterable object.
  376. * @param arrayLike An array-like or iterable object to convert to an array.
  377. * @param mapfn A mapping function to call on every element of the array.
  378. * @param thisArg Value of 'this' used to invoke the mapfn.
  379. */
  380. from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
  381. }