es6-promise.d.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. interface Symbol {
  16. /** Returns a string representation of an object. */
  17. toString(): string;
  18. /** Returns the primitive value of the specified object. */
  19. valueOf(): Object;
  20. //[Symbol.toStringTag]: "Symbol";
  21. }
  22. interface SymbolConstructor {
  23. /**
  24. * A reference to the prototype.
  25. */
  26. prototype: Symbol;
  27. /**
  28. * Returns a new unique Symbol value.
  29. * @param description Description of the new Symbol object.
  30. */
  31. (description?: string|number): symbol;
  32. /**
  33. * Returns a Symbol object from the global symbol registry matching the given key if found.
  34. * Otherwise, returns a new symbol with this key.
  35. * @param key key to search for.
  36. */
  37. for(key: string): symbol;
  38. /**
  39. * Returns a key from the global symbol registry matching the given Symbol if found.
  40. * Otherwise, returns a undefined.
  41. * @param sym Symbol to find the key for.
  42. */
  43. keyFor(sym: symbol): string;
  44. // Well-known Symbols
  45. /**
  46. * A method that determines if a constructor object recognizes an object as one of the
  47. * constructor’s instances. Called by the semantics of the instanceof operator.
  48. */
  49. hasInstance: symbol;
  50. /**
  51. * A Boolean value that if true indicates that an object should flatten to its array elements
  52. * by Array.prototype.concat.
  53. */
  54. isConcatSpreadable: symbol;
  55. /**
  56. * A method that returns the default iterator for an object. Called by the semantics of the
  57. * for-of statement.
  58. */
  59. iterator: symbol;
  60. /**
  61. * A regular expression method that matches the regular expression against a string. Called
  62. * by the String.prototype.match method.
  63. */
  64. match: symbol;
  65. /**
  66. * A regular expression method that replaces matched substrings of a string. Called by the
  67. * String.prototype.replace method.
  68. */
  69. replace: symbol;
  70. /**
  71. * A regular expression method that returns the index within a string that matches the
  72. * regular expression. Called by the String.prototype.search method.
  73. */
  74. search: symbol;
  75. /**
  76. * A function valued property that is the constructor function that is used to create
  77. * derived objects.
  78. */
  79. species: symbol;
  80. /**
  81. * A regular expression method that splits a string at the indices that match the regular
  82. * expression. Called by the String.prototype.split method.
  83. */
  84. split: symbol;
  85. /**
  86. * A method that converts an object to a corresponding primitive value.
  87. * Called by the ToPrimitive abstract operation.
  88. */
  89. toPrimitive: symbol;
  90. /**
  91. * A String value that is used in the creation of the default string description of an object.
  92. * Called by the built-in method Object.prototype.toString.
  93. */
  94. toStringTag: symbol;
  95. /**
  96. * An Object whose own property names are property names that are excluded from the 'with'
  97. * environment bindings of the associated objects.
  98. */
  99. unscopables: symbol;
  100. }
  101. declare var Symbol: SymbolConstructor;
  102. interface IteratorResult<T> {
  103. done: boolean;
  104. value?: T;
  105. }
  106. interface Iterator<T> {
  107. next(value?: any): IteratorResult<T>;
  108. return?(value?: any): IteratorResult<T>;
  109. throw?(e?: any): IteratorResult<T>;
  110. }
  111. interface Iterable<T> {
  112. [Symbol.iterator](): Iterator<T>;
  113. }
  114. /**
  115. * Represents the completion of an asynchronous operation
  116. */
  117. interface Promise<T> {
  118. /**
  119. * Attaches callbacks for the resolution and/or rejection of the Promise.
  120. * @param onfulfilled The callback to execute when the Promise is resolved.
  121. * @param onrejected The callback to execute when the Promise is rejected.
  122. * @returns A Promise for the completion of which ever callback is executed.
  123. */
  124. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
  125. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
  126. /**
  127. * Attaches a callback for only the rejection of the Promise.
  128. * @param onrejected The callback to execute when the Promise is rejected.
  129. * @returns A Promise for the completion of the callback.
  130. */
  131. catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
  132. catch(onrejected?: (reason: any) => void): Promise<T>;
  133. //[Symbol.toStringTag]: "Promise";
  134. }
  135. interface PromiseConstructor {
  136. /**
  137. * A reference to the prototype.
  138. */
  139. prototype: Promise<any>;
  140. /**
  141. * Creates a new Promise.
  142. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  143. * a resolve callback used resolve the promise with a value or the result of another promise,
  144. * and a reject callback used to reject the promise with a provided reason or error.
  145. */
  146. new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
  147. /**
  148. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  149. * resolve, or rejected when any Promise is rejected.
  150. * @param values An array of Promises.
  151. * @returns A new Promise.
  152. */
  153. all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
  154. all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
  155. all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>]): Promise<[T1, T2, T3, T4]>;
  156. 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]>;
  157. 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]>;
  158. 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]>;
  159. 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]>;
  160. 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]>;
  161. 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]>;
  162. all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;
  163. /**
  164. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  165. * or rejected.
  166. * @param values An array of Promises.
  167. * @returns A new Promise.
  168. */
  169. race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
  170. /**
  171. * Creates a new rejected promise for the provided reason.
  172. * @param reason The reason the promise was rejected.
  173. * @returns A new rejected Promise.
  174. */
  175. reject(reason: any): Promise<void>;
  176. /**
  177. * Creates a new rejected promise for the provided reason.
  178. * @param reason The reason the promise was rejected.
  179. * @returns A new rejected Promise.
  180. */
  181. reject<T>(reason: any): Promise<T>;
  182. /**
  183. * Creates a new resolved promise for the provided value.
  184. * @param value A promise.
  185. * @returns A promise whose internal state matches the provided promise.
  186. */
  187. resolve<T>(value: T | PromiseLike<T>): Promise<T>;
  188. /**
  189. * Creates a new resolved promise .
  190. * @returns A resolved promise.
  191. */
  192. resolve(): Promise<void>;
  193. [Symbol.species]: Function;
  194. }
  195. declare var Promise: PromiseConstructor;
  196. // *just* for jupyter-js-services, which uses a different name.
  197. declare type Thenable<T> = PromiseLike<T>;