# @types/async-retry

> TypeScript definitions for async-retry

Latest version **1.4.9** (published 2024-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/async-retry
pnpm add @types/async-retry
yarn add @types/async-retry
bun add @types/async-retry
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.4.9 |
| Published | 2024-10-02 |
| First published | 2018-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51441 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/async-retry
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry
- npm.io page: https://npm.io/package/@types/async-retry

## Dependencies (1)

- [@types/retry](https://npm.io/package/@types/retry.md) *

## Recent versions

- 1.4.9 (latest) — 2024-10-02
- 1.4.8 (ts4.5) — 2023-11-06
- 1.4.5 (ts4.4) — 2022-08-19
- 1.4.4 (ts3.9) — 2022-04-26
- 1.4.3 (ts3.6) — 2021-07-06
- 1.4.2 (ts3.3) — 2020-05-15
- 1.4.1 (ts2.6) — 2019-04-15
- 1.3.0 (ts2.1) — 2019-04-01
- 1.4.7 — 2023-10-17
- 1.4.6 — 2023-09-22
- 1.4.0 — 2019-04-04
- 1.2.1 — 2018-06-05
- 1.2.0 — 2018-04-02
- 1.1.0 — 2018-01-25

## README

# Installation
> `npm install --save @types/async-retry`

# Summary
This package contains type definitions for async-retry (https://github.com/vercel/async-retry).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry/index.d.ts)
````ts
import { WrapOptions } from "retry";

/**
 * Retrying made simple, easy, and async.
 *
 * @example
 * import retry = require('async-retry');
 * import fetch from '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);
 *   },
 *   {
 *     retries: 5,
 *   }
 * );
 */
declare function AsyncRetry<TRet, TErr = unknown>(
    fn: AsyncRetry.RetryFunction<TRet, TErr>,
    opts?: AsyncRetry.Options<TErr> | number[],
): Promise<TRet>;

declare namespace AsyncRetry {
    interface Options<TErr = unknown> extends Omit<WrapOptions, "randomize"> {
        /**
         * An optional function that is invoked after a new retry is performed. It's passed the
         * `Error` that triggered it as a parameter.
         */
        onRetry?: ((e: TErr, attempt: number) => any) | undefined;
        /**
         * Randomizes the timeouts by multiplying a factor between 1-2.
         * @default true
         */
        randomize?: boolean | undefined;
    }

    /**
     * @param bail A function you can invoke to abort the retrying (bail).
     * @param attempt The attempt number. The absolute first attempt (before any retries) is `1`.
     */
    type RetryFunction<TRet, TErr = unknown> = (bail: (e: TErr) => void, attempt: number) => TRet | Promise<TRet>;
}

export = AsyncRetry;

````

### Additional Details
 * Last updated: Wed, 02 Oct 2024 18:10:02 GMT
 * Dependencies: [@types/retry](https://npmjs.com/package/@types/retry)

# Credits
These definitions were written by [Albert Wu](https://github.com/albertywu), [Pablo Rodríguez](https://github.com/MeLlamoPablo), [Rafał Sawicki](https://github.com/rafsawicki), and [BendingBender](https://github.com/BendingBender).

---
_Source: https://npm.io/package/@types/async-retry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
