You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
775B

  1. /**
  2. Create a type that represents either the value or the value wrapped in `PromiseLike`.
  3. Use-cases:
  4. - A function accepts a callback that may either return a value synchronously or may return a promised value.
  5. - This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
  6. Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
  7. @example
  8. ```
  9. import {Promisable} from 'type-fest';
  10. async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
  11. const entry = await getLogEntry();
  12. console.log(entry);
  13. }
  14. logger(() => 'foo');
  15. logger(() => Promise.resolve('bar'));
  16. ```
  17. */
  18. export type Promisable<T> = T | PromiseLike<T>;