Promise.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @flow strict
  8. * @format
  9. */
  10. // These annotations are copy/pasted from the built-in Flow definitions for
  11. // Native Promises with some non-standard APIs added in
  12. declare class Promise<+R> {
  13. constructor(
  14. callback: (
  15. resolve: (result?: Promise<R> | R) => void,
  16. reject: (error?: any) => void,
  17. ) => mixed,
  18. ): void;
  19. then<U>(
  20. onFulfill?: ?(value: R) => Promise<U> | ?U,
  21. onReject?: ?(error: any) => Promise<U> | ?U,
  22. ): Promise<U>;
  23. catch<U>(onReject?: (error: any) => ?Promise<U> | U): Promise<U>;
  24. static resolve<T>(object?: Promise<T> | T): Promise<T>;
  25. static reject<T>(error?: any): Promise<T>;
  26. static all<T: Iterable<mixed>>(
  27. promises: T,
  28. ): Promise<$TupleMap<T, typeof $await>>;
  29. static race<T>(promises: Array<Promise<T>>): Promise<T>;
  30. // Non-standard APIs
  31. // See https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/__forks__/Promise.native.js#L21
  32. finally<U>(onFinally?: ?(value: any) => Promise<U> | U): Promise<U>;
  33. done<U>(
  34. onFulfill?: ?(value: R) => mixed,
  35. onReject?: ?(error: any) => mixed,
  36. ): void;
  37. static cast<T>(object?: T): Promise<T>;
  38. }