lib.es2015.promise.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*! *****************************************************************************
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  4. this file except in compliance with the License. You may obtain a copy of the
  5. License at http://www.apache.org/licenses/LICENSE-2.0
  6. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  8. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  9. MERCHANTABLITY OR NON-INFRINGEMENT.
  10. See the Apache Version 2.0 License for specific language governing permissions
  11. and limitations under the License.
  12. ***************************************************************************** */
  13. /// <reference no-default-lib="true"/>
  14. interface PromiseConstructor {
  15. /**
  16. * A reference to the prototype.
  17. */
  18. readonly prototype: Promise<any>;
  19. /**
  20. * Creates a new Promise.
  21. * @param executor A callback used to initialize the promise. This callback is passed two arguments:
  22. * a resolve callback used to resolve the promise with a value or the result of another promise,
  23. * and a reject callback used to reject the promise with a provided reason or error.
  24. */
  25. new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
  26. /**
  27. * Creates a Promise that is resolved with an array of results when all of the provided Promises
  28. * resolve, or rejected when any Promise is rejected.
  29. * @param values An array of Promises.
  30. * @returns A new Promise.
  31. */
  32. all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }>;
  33. // see: lib.es2015.iterable.d.ts
  34. // all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
  35. /**
  36. * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
  37. * or rejected.
  38. * @param values An array of Promises.
  39. * @returns A new Promise.
  40. */
  41. race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
  42. // see: lib.es2015.iterable.d.ts
  43. // race<T>(values: Iterable<T>): Promise<T extends PromiseLike<infer U> ? U : T>;
  44. /**
  45. * Creates a new rejected promise for the provided reason.
  46. * @param reason The reason the promise was rejected.
  47. * @returns A new rejected Promise.
  48. */
  49. reject<T = never>(reason?: any): Promise<T>;
  50. /**
  51. * Creates a new resolved promise.
  52. * @returns A resolved promise.
  53. */
  54. resolve(): Promise<void>;
  55. /**
  56. * Creates a new resolved promise for the provided value.
  57. * @param value A promise.
  58. * @returns A promise whose internal state matches the provided promise.
  59. */
  60. resolve<T>(value: T | PromiseLike<T>): Promise<T>;
  61. }
  62. declare var Promise: PromiseConstructor;