es6-promise.d.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 PromiseLike<T> {
  136. /**
  137. * Attaches callbacks for the resolution and/or rejection of the Promise.
  138. * @param onfulfilled The callback to execute when the Promise is resolved.
  139. * @param onrejected The callback to execute when the Promise is rejected.
  140. * @returns A Promise for the completion of which ever callback is executed.
  141. */
  142. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
  143. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
  144. }
  145. interface PromiseConstructor {
  146. /**
  147. * A reference to the prototype.
  148. */
  149. prototype: Promise<any>;
  150. /**
  151. * Creates a new Promise.
  152. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  153. * a resolve callback used resolve the promise with a value or the result of another promise,
  154. * and a reject callback used to reject the promise with a provided reason or error.
  155. */
  156. new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
  157. /**
  158. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  159. * resolve, or rejected when any Promise is rejected.
  160. * @param values An array of Promises.
  161. * @returns A new Promise.
  162. */
  163. all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
  164. all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
  165. all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>]): Promise<[T1, T2, T3, T4]>;
  166. 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]>;
  167. 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]>;
  168. 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]>;
  169. 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]>;
  170. 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]>;
  171. 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]>;
  172. all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;
  173. /**
  174. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  175. * or rejected.
  176. * @param values An array of Promises.
  177. * @returns A new Promise.
  178. */
  179. race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
  180. /**
  181. * Creates a new rejected promise for the provided reason.
  182. * @param reason The reason the promise was rejected.
  183. * @returns A new rejected Promise.
  184. */
  185. reject(reason: any): Promise<void>;
  186. /**
  187. * Creates a new rejected promise for the provided reason.
  188. * @param reason The reason the promise was rejected.
  189. * @returns A new rejected Promise.
  190. */
  191. reject<T>(reason: any): Promise<T>;
  192. /**
  193. * Creates a new resolved promise for the provided value.
  194. * @param value A promise.
  195. * @returns A promise whose internal state matches the provided promise.
  196. */
  197. resolve<T>(value: T | PromiseLike<T>): Promise<T>;
  198. /**
  199. * Creates a new resolved promise .
  200. * @returns A resolved promise.
  201. */
  202. resolve(): Promise<void>;
  203. [Symbol.species]: Function;
  204. }
  205. declare var Promise: PromiseConstructor;
  206. // *just* for jupyter-js-services, which uses a different name.
  207. declare type Thenable<T> = PromiseLike<T>;