index.d.ts 706 B

123456789101112131415161718192021222324252627
  1. /**
  2. Start a promise chain.
  3. @param fn - The function to run to start the promise chain.
  4. @param arguments - Arguments to pass to `fn`.
  5. @returns The value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.
  6. @example
  7. ```
  8. import pTry from 'p-try';
  9. (async () => {
  10. try {
  11. const value = await pTry(() => {
  12. return synchronousFunctionThatMightThrow();
  13. });
  14. console.log(value);
  15. } catch (error) {
  16. console.error(error);
  17. }
  18. })();
  19. ```
  20. */
  21. export default function pTry<ValueType, ArgumentsType extends unknown[]>(
  22. fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
  23. ...arguments: ArgumentsType
  24. ): Promise<ValueType>;