es6-promise.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // ES6 Promises
  2. // From https://github.com/Microsoft/TypeScript/blob/0aef9440f28609ead886a1745f52d2a517326fde/lib/lib.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 SymbolConstructor {
  16. /**
  17. * A reference to the prototype.
  18. */
  19. prototype: Symbol;
  20. /**
  21. * Returns a new unique Symbol value.
  22. * @param description Description of the new Symbol object.
  23. */
  24. (description?: string|number): symbol;
  25. /**
  26. * Returns a Symbol object from the global symbol registry matching the given key if found.
  27. * Otherwise, returns a new symbol with this key.
  28. * @param key key to search for.
  29. */
  30. for(key: string): symbol;
  31. /**
  32. * Returns a key from the global symbol registry matching the given Symbol if found.
  33. * Otherwise, returns a undefined.
  34. * @param sym Symbol to find the key for.
  35. */
  36. keyFor(sym: symbol): string;
  37. // Well-known Symbols
  38. /**
  39. * A method that determines if a constructor object recognizes an object as one of the
  40. * constructor’s instances. Called by the semantics of the instanceof operator.
  41. */
  42. hasInstance: symbol;
  43. /**
  44. * A Boolean value that if true indicates that an object should flatten to its array elements
  45. * by Array.prototype.concat.
  46. */
  47. isConcatSpreadable: symbol;
  48. /**
  49. * A method that returns the default iterator for an object. Called by the semantics of the
  50. * for-of statement.
  51. */
  52. iterator: symbol;
  53. /**
  54. * A regular expression method that matches the regular expression against a string. Called
  55. * by the String.prototype.match method.
  56. */
  57. match: symbol;
  58. /**
  59. * A regular expression method that replaces matched substrings of a string. Called by the
  60. * String.prototype.replace method.
  61. */
  62. replace: symbol;
  63. /**
  64. * A regular expression method that returns the index within a string that matches the
  65. * regular expression. Called by the String.prototype.search method.
  66. */
  67. search: symbol;
  68. /**
  69. * A function valued property that is the constructor function that is used to create
  70. * derived objects.
  71. */
  72. species: symbol;
  73. /**
  74. * A regular expression method that splits a string at the indices that match the regular
  75. * expression. Called by the String.prototype.split method.
  76. */
  77. split: symbol;
  78. /**
  79. * A method that converts an object to a corresponding primitive value.
  80. * Called by the ToPrimitive abstract operation.
  81. */
  82. toPrimitive: symbol;
  83. /**
  84. * A String value that is used in the creation of the default string description of an object.
  85. * Called by the built-in method Object.prototype.toString.
  86. */
  87. toStringTag: symbol;
  88. /**
  89. * An Object whose own property names are property names that are excluded from the 'with'
  90. * environment bindings of the associated objects.
  91. */
  92. unscopables: symbol;
  93. }
  94. declare var Symbol: SymbolConstructor;
  95. interface Symbol {
  96. /** Returns a string representation of an object. */
  97. toString(): string;
  98. /** Returns the primitive value of the specified object. */
  99. valueOf(): Object;
  100. [Symbol.toStringTag]: string;
  101. }
  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. }
  134. interface PromiseLike<T> {
  135. /**
  136. * Attaches callbacks for the resolution and/or rejection of the Promise.
  137. * @param onfulfilled The callback to execute when the Promise is resolved.
  138. * @param onrejected The callback to execute when the Promise is rejected.
  139. * @returns A Promise for the completion of which ever callback is executed.
  140. */
  141. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
  142. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
  143. }
  144. interface PromiseConstructor {
  145. /**
  146. * A reference to the prototype.
  147. */
  148. prototype: Promise<any>;
  149. /**
  150. * Creates a new Promise.
  151. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  152. * a resolve callback used resolve the promise with a value or the result of another promise,
  153. * and a reject callback used to reject the promise with a provided reason or error.
  154. */
  155. new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
  156. /**
  157. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  158. * resolve, or rejected when any Promise is rejected.
  159. * @param values An array of Promises.
  160. * @returns A new Promise.
  161. */
  162. all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
  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>;