es6-promise.es6.d.ts 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. interface PromiseLike<T> {
  2. /**
  3. * Attaches callbacks for the resolution and/or rejection of the Promise.
  4. * @param onfulfilled The callback to execute when the Promise is resolved.
  5. * @param onrejected The callback to execute when the Promise is rejected.
  6. * @returns A Promise for the completion of which ever callback is executed.
  7. */
  8. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
  9. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
  10. }
  11. /**
  12. * Represents the completion of an asynchronous operation
  13. */
  14. interface Promise<T> {
  15. /**
  16. * Attaches callbacks for the resolution and/or rejection of the Promise.
  17. * @param onfulfilled The callback to execute when the Promise is resolved.
  18. * @param onrejected The callback to execute when the Promise is rejected.
  19. * @returns A Promise for the completion of which ever callback is executed.
  20. */
  21. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
  22. then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
  23. /**
  24. * Attaches a callback for only the rejection of the Promise.
  25. * @param onrejected The callback to execute when the Promise is rejected.
  26. * @returns A Promise for the completion of the callback.
  27. */
  28. catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
  29. catch(onrejected?: (reason: any) => void): Promise<T>;
  30. [Symbol.toStringTag]: string;
  31. }
  32. interface PromiseConstructor {
  33. /**
  34. * A reference to the prototype.
  35. */
  36. prototype: Promise<any>;
  37. /**
  38. * Creates a new Promise.
  39. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  40. * a resolve callback used resolve the promise with a value or the result of another promise,
  41. * and a reject callback used to reject the promise with a provided reason or error.
  42. */
  43. new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
  44. /**
  45. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  46. * resolve, or rejected when any Promise is rejected.
  47. * @param values An array of Promises.
  48. * @returns A new Promise.
  49. */
  50. all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
  51. /**
  52. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  53. * or rejected.
  54. * @param values An array of Promises.
  55. * @returns A new Promise.
  56. */
  57. race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
  58. /**
  59. * Creates a new rejected promise for the provided reason.
  60. * @param reason The reason the promise was rejected.
  61. * @returns A new rejected Promise.
  62. */
  63. reject(reason: any): Promise<void>;
  64. /**
  65. * Creates a new rejected promise for the provided reason.
  66. * @param reason The reason the promise was rejected.
  67. * @returns A new rejected Promise.
  68. */
  69. reject<T>(reason: any): Promise<T>;
  70. /**
  71. * Creates a new resolved promise for the provided value.
  72. * @param value A promise.
  73. * @returns A promise whose internal state matches the provided promise.
  74. */
  75. resolve<T>(value: T | PromiseLike<T>): Promise<T>;
  76. /**
  77. * Creates a new resolved promise .
  78. * @returns A resolved promise.
  79. */
  80. resolve(): Promise<void>;
  81. [Symbol.species]: Function;
  82. }
  83. declare var Promise: PromiseConstructor;