vercel / async-retry

Retrying made simple, easy and async
https://npmjs.com/async-retry
MIT License
1.85k stars 53 forks source link

Option has no retries #97

Open ghost opened 2 years ago

ghost commented 2 years ago

I haven't followed the details of whether the type of @types/retry has changed, but I got an error that option has no "retries", and I couldn't use this package.

const retry = require('async-retry');
const fetch = require('node-fetch');

await retry(
  async (bail) => {
    // if anything throws, we retry
    const res = await fetch('https://google.com');

    if (403 === res.status) {
      // don't retry upon 403
      bail(new Error('Unauthorized'));
      return;
    }

    const data = await res.text();
    return data.substr(0, 500);
  },
  {
   // Not Found
    retries: 5,
  }
);
mattsputnikdigital commented 2 years ago

Im having this issue as well.

mattsputnikdigital commented 2 years ago

@yogarasu are you using Typescript 3 or 4. I had this issue when using the latest version of the types package on TS3.

Fix the @types package at 1.3.0 and the issue may also go away.

eXigentCoder commented 2 years ago

Can confirm that npm i -D @types/async-retry@1.3.0 works, the latest version of the types definition has this code:

import { WrapOptions } from 'retry';

But the version of @types/retry that got automatically downloaded didn't have that (I'm using typescript@4.8.3).

Managed to fix it by running npm i -D @types/retry@latest @types/async-retry@latest

ymansurozer commented 1 year ago

Installing @types/retry solved it for me.

vitaly-t commented 2 months ago

A simpler but more flexible solution in TypeScript 😉