Skip to content

TypeScript · correctness

require-fetch-timeout

eslint:require-fetch-timeout

Require an abort `signal` (e.g. `AbortSignal.timeout(ms)`) on global `fetch()` calls so stalled upstreams cannot hang the caller forever.

Default
error
Fix
none
Languages
typescript

Why

An unbounded request can occupy work indefinitely when an upstream stalls.

Fix

Pass an abort signal, such as `AbortSignal.timeout(ms)`, in the fetch init.

Before / after

Executed by this rule’s unit tests.

Before

Do not leave fetch unbounded

src/client.ts · focus
await fetch('https://api.example.com/items');

After

Bound the request

src/client.ts · focus
await fetch(url, { signal: AbortSignal.timeout(5000) });

Message IDs

missingSignal

Options

{
  "additionalProperties": false,
  "properties": {
    "allowIn": {
      "description": "Glob patterns for wrapper modules exempt from the rule. Matched against the ABSOLUTE file path, so anchor with a `**/` prefix (e.g. `**/http-client.ts`).",
      "items": {
        "type": "string"
      },
      "type": "array"
    }
  },
  "type": "object"
}