es6-promise.d.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // ES6 Promises
  2. // From https://github.com/Microsoft/TypeScript/blob/911d07a81b9348dd576985f263955c8e0968277e/lib/lib.core.es6.d.ts
  3. /*! *****************************************************************************
  4. Copyright (c) Microsoft Corporation. All rights reserved.
  5. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  6. this file except in compliance with the License. You may obtain a copy of the
  7. License at http://www.apache.org/licenses/LICENSE-2.0
  8. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  9. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  10. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  11. MERCHANTABLITY OR NON-INFRINGEMENT.
  12. See the Apache Version 2.0 License for specific language governing permissions
  13. and limitations under the License.
  14. ***************************************************************************** */
  15. /// <reference path="../es6-collections/es6-collections.d.ts"/>
  16. interface Symbol {
  17. /** Returns a string representation of an object. */
  18. toString(): string;
  19. /** Returns the primitive value of the specified object. */
  20. valueOf(): Object;
  21. //[Symbol.toStringTag]: "Symbol";
  22. }
  23. interface SymbolConstructor {
  24. /**
  25. * A reference to the prototype.
  26. */
  27. prototype: Symbol;
  28. /**
  29. * Returns a new unique Symbol value.
  30. * @param description Description of the new Symbol object.
  31. */
  32. (description?: string|number): symbol;
  33. /**
  34. * Returns a Symbol object from the global symbol registry matching the given key if found.
  35. * Otherwise, returns a new symbol with this key.
  36. * @param key key to search for.
  37. */
  38. for(key: string): symbol;
  39. /**
  40. * Returns a key from the global symbol registry matching the given Symbol if found.
  41. * Otherwise, returns a undefined.
  42. * @param sym Symbol to find the key for.
  43. */
  44. keyFor(sym: symbol): string;
  45. // Well-known Symbols
  46. /**
  47. * A method that determines if a constructor object recognizes an object as one of the
  48. * constructor’s instances. Called by the semantics of the instanceof operator.
  49. */
  50. hasInstance: symbol;
  51. /**
  52. * A Boolean value that if true indicates that an object should flatten to its array elements
  53. * by Array.prototype.concat.
  54. */
  55. isConcatSpreadable: symbol;
  56. /**
  57. * A method that returns the default iterator for an object. Called by the semantics of the
  58. * for-of statement.
  59. */
  60. iterator: symbol;
  61. /**
  62. * A regular expression method that matches the regular expression against a string. Called
  63. * by the String.prototype.match method.
  64. */
  65. match: symbol;
  66. /**
  67. * A regular expression method that replaces matched substrings of a string. Called by the
  68. * String.prototype.replace method.
  69. */
  70. replace: symbol;
  71. /**
  72. * A regular expression method that returns the index within a string that matches the
  73. * regular expression. Called by the String.prototype.search method.
  74. */
  75. search: symbol;
  76. /**
  77. * A function valued property that is the constructor function that is used to create
  78. * derived objects.
  79. */
  80. species: symbol;
  81. /**
  82. * A regular expression method that splits a string at the indices that match the regular
  83. * expression. Called by the String.prototype.split method.
  84. */
  85. split: symbol;
  86. /**
  87. * A method that converts an object to a corresponding primitive value.
  88. * Called by the ToPrimitive abstract operation.
  89. */
  90. toPrimitive: symbol;
  91. /**
  92. * A String value that is used in the creation of the default string description of an object.
  93. * Called by the built-in method Object.prototype.toString.
  94. */
  95. toStringTag: symbol;
  96. /**
  97. * An Object whose own property names are property names that are excluded from the 'with'
  98. * environment bindings of the associated objects.
  99. */
  100. unscopables: symbol;
  101. }
  102. declare var Symbol: SymbolConstructor;
  103. interface Iterable<T> {
  104. //[Symbol.iterator](): Iterator<T>;
  105. }
  106. /**
  107. * Represents the completion of an asynchronous operation
  108. */
  109. interface Promise<T> {
  110. /**
  111. * Attaches callbacks for the resolution and/or rejection of the Promise.
  112. * @param onfulfilled The callback to execute when the Promise is resolved.
  113. * @param onrejected The callback to execute when the Promise is rejected.
  114. * @returns A Promise for the completion of which ever callback is executed.
  115. */
  116. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
  117. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
  118. /**
  119. * Attaches a callback for only the rejection of the Promise.
  120. * @param onrejected The callback to execute when the Promise is rejected.
  121. * @returns A Promise for the completion of the callback.
  122. */
  123. catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
  124. catch(onrejected?: (reason: any) => void): Promise<T>;
  125. //[Symbol.toStringTag]: "Promise";
  126. }
  127. interface PromiseLike<T> {
  128. /**
  129. * Attaches callbacks for the resolution and/or rejection of the Promise.
  130. * @param onfulfilled The callback to execute when the Promise is resolved.
  131. * @param onrejected The callback to execute when the Promise is rejected.
  132. * @returns A Promise for the completion of which ever callback is executed.
  133. */
  134. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
  135. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
  136. }
  137. interface PromiseConstructor {
  138. /**
  139. * A reference to the prototype.
  140. */
  141. prototype: Promise<any>;
  142. /**
  143. * Creates a new Promise.
  144. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  145. * a resolve callback used resolve the promise with a value or the result of another promise,
  146. * and a reject callback used to reject the promise with a provided reason or error.
  147. */
  148. new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
  149. /**
  150. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  151. * resolve, or rejected when any Promise is rejected.
  152. * @param values An array of Promises.
  153. * @returns A new Promise.
  154. */
  155. all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
  156. all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
  157. all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>]): Promise<[T1, T2, T3, T4]>;
  158. all<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
  159. all<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
  160. all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
  161. all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
  162. all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
  163. all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
  164. all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;
  165. /**
  166. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  167. * or rejected.
  168. * @param values An array of Promises.
  169. * @returns A new Promise.
  170. */
  171. race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
  172. /**
  173. * Creates a new rejected promise for the provided reason.
  174. * @param reason The reason the promise was rejected.
  175. * @returns A new rejected Promise.
  176. */
  177. reject(reason: any): Promise<void>;
  178. /**
  179. * Creates a new rejected promise for the provided reason.
  180. * @param reason The reason the promise was rejected.
  181. * @returns A new rejected Promise.
  182. */
  183. reject<T>(reason: any): Promise<T>;
  184. /**
  185. * Creates a new resolved promise for the provided value.
  186. * @param value A promise.
  187. * @returns A promise whose internal state matches the provided promise.
  188. */
  189. resolve<T>(value: T | PromiseLike<T>): Promise<T>;
  190. /**
  191. * Creates a new resolved promise .
  192. * @returns A resolved promise.
  193. */
  194. resolve(): Promise<void>;
  195. [Symbol.species]: Function;
  196. }
  197. declare var Promise: PromiseConstructor;
  198. // *just* for jupyter-js-services, which uses a different name.
  199. declare type Thenable<T> = PromiseLike<T>;