Skip to content

fix(types): accept config in getAdapter - #11404

Merged
jasonsaayman merged 5 commits into
axios:v1.xfrom
aelmanaa:fix/get-adapter-config-type
Nov 2, 2026
Merged

jasonsaayman merged 5 commits into
axios:v1.xfrom
aelmanaa:fix/get-adapter-config-type

Conversation

@aelmanaa

@aelmanaa aelmanaa commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

getAdapter(adapters, config) forwards config to adapter getters at runtime (the fetch adapter reads config.env.fetch / Request / Response through getFetch(config)), but the typings declared only adapters. Calling getAdapter('fetch', { env: { fetch: myFetch } }) from TypeScript failed with TS2554 and needed a cast.

Linked issue

Closes #11403

Changes

  • index.d.ts / index.d.cts: getAdapter takes an optional config?: AxiosRequestConfig, with a JSDoc comment saying the built-in fetch adapter reads env.fetch, env.Request, and env.Response from it and that other fields are not applied.
  • ESM and CJS fetch type fixtures: positive cases (single name, list, undefined, adapter function) and a @ts-expect-error for a non-function env.fetch. The existing @ts-expect-error getAdapter('xhr', 'http') still errors.
  • Unit test: getAdapter passes the config through to an adapter's get.
  • PRE_RELEASE_CHANGELOG.md: Bug Fixes entry, linking getAdapter typings omit the config argument #11403 and this PR.
  • PRE_RELEASE_DOCS.md: pending entry for the getAdapter section of the docs-site API reference (docs/pages/advanced/api-reference.md and its es/fr/zh translations), which still shows getAdapter(adapters: string | string[]).
  • Merged v1.x into the branch to resolve a PRE_RELEASE_CHANGELOG.md conflict; both Bug Fixes entries are kept.

Validation

Node 24.21.0, npm 11.19.0, after npm ci --ignore-scripts:

  • npm run lint: passes
  • npm run build: passes
  • npm run test:vitest:unit: 74 files, 1701 tests pass
  • npm pack, then in tests/module/cjs and tests/module/esm: npm install --ignore-scripts, npm install --no-save ../../../axios-1.21.0.tgz, npm run test:module:{cjs,esm}: both pass (CJS 8 passing, ESM 9 passing)
  • Regression check: with index.d.ts / index.d.cts reverted and repacked, both module suites fail with error TS2554: Expected 1 arguments, but got 2. on the new fixture lines.
  • Browser suite not run: there is no runtime or adapter change.

Maintainer re-run after the merge with v1.x and the JSDoc/docs-tracking commit (8345176d), Node 24.21.0, after npm ci --ignore-scripts:

  • npm run lint: passes
  • npm run build: passes
  • npm run test:vitest:unit: 74 files, 1705 tests pass
  • npm pack, then npm run test:module:cjs (8 passing) and npm run test:module:esm (9 passing) against the tarball
  • prettier --check reports no issues on the new getAdapter lines (the existing warnings in index.d.ts / index.d.cts are already on v1.x)

GitHub Actions: fork run approval required; status to be confirmed on the latest commit.

Compatibility and documentation

Patch, type-only. The new parameter is optional, so existing calls are unchanged. No runtime change. getAdapter is not in the README, but the docs-site API reference documents its signature, so the update is tracked in PRE_RELEASE_DOCS.md for release preparation, following AGENTS.md.

Checklist

  • Scope, target branch, and linked issue/rationale checked
  • PRE_RELEASE_CHANGELOG.md entry added or updated (or AGENTS.md's automated release-preparation exception explained)
  • Regression tests and relevant negative/platform cases covered (or N/A with reason)
  • Applicable local checks completed, with actual commands and results recorded above
  • Deferred release docs and ESM/CJS types/tests updated where needed (or N/A with reason)
  • Semver impact stated and intentional breaking changes explained
  • Final diff reviewed for security, unrelated changes, generated artifacts, and test/debug leftovers
  • Latest GitHub Actions status recorded separately from review/security bot results

AI-assisted. I could not apply the ai-assisted label from a fork, so a maintainer needs to apply it.

🤖 Generated with Claude Code


Summary by cubic

Description

getAdapter now accepts an optional request config in its TypeScript typings, matching the runtime behavior that already forwards config to adapter getters (the fetch adapter reads config.env.fetch through getFetch(config)). Previously, calls like getAdapter('fetch', { env: { fetch: myFetch } }) failed to type-check with TS2554 and required a cast; the 2.0-beta typings still declared only adapters.

  • index.d.ts and index.d.cts: getAdapter takes an optional config?: AxiosRequestConfig, with a JSDoc comment noting the built-in fetch adapter reads env.fetch, env.Request, and env.Response from it.
  • Added positive and negative type fixtures to both the CJS and ESM fetch type tests, plus a unit test verifying the config is passed through to an adapter's get.
  • Type-only, additive change; existing calls are unaffected. No runtime change. Closes getAdapter typings omit the config argument #11403.

Docs

getAdapter is not documented in the README; an update for the docs-site API reference is tracked in PRE_RELEASE_DOCS.md.

Testing

Added @ts-expect-error and positive type fixtures covering single name, list, undefined, and adapter function in both module suites, plus a unit test asserting the config object is forwarded to adapter getters. Validation passed for lint, build, the unit suite (1705 tests), and both CJS and ESM module type tests; a regression check with the typings reverted confirmed the new fixtures fail with TS2554.

Semantic version impact

Patch: type-only, additive, and backwards compatible. No runtime change.

Written for commit 8e663ed. Summary will update on new commits.

View guided diff

@aelmanaa

Copy link
Copy Markdown
Contributor Author

@jasonsaayman small type-only fix for #11403. Could you also apply ai-assisted? I can't set labels from a fork.

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The reviewed changes are safe to merge; no blocking issues were identified.

Summary

Adds an optional config argument to the ESM and CJS getAdapter types, matching existing runtime behavior.

  • getAdapter calls can include an optional config in TypeScript.

Reviews (4) · Last reviewed commit: "chore: update PRE_RELEASE_DOCS.md" · Reviewed by Greptile

@charan-rathore

Copy link
Copy Markdown

One small type-test addition worth considering: the new fixtures cover named adapters and lists, but the first argument also accepts undefined and a direct adapter function.

On 503f30b, strict ESM TypeScript checks pass for both axios.getAdapter(undefined, config) and axios.getAdapter(adapterFunction, config), with config containing timeout and env.fetch. An invalid string timeout still produces the expected type error. Reverting only the declaration to its old one-argument signature makes those valid two-argument calls fail with TS2554.

Keeping those two positive cases in the fixtures would pin the optional config argument across the other supported adapter forms too. This is optional coverage, not a defect in the current change. AI-assisted testing; I haven't rerun the full module/browser matrix.

@aelmanaa

aelmanaa commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@charan-rathore thanks, added both cases (undefined and an adapter function, each with a config) to the ESM and CJS fixtures in 31a2b1a. Both module suites pass.

@jasonsaayman jasonsaayman added commit::fix The PR is related to a bugfix v1x Version 1 labels Nov 2, 2026
…g-type

# Conflicts:
#	PRE_RELEASE_CHANGELOG.md
Add a JSDoc comment to the getAdapter config parameter in index.d.ts and
index.d.cts, track the docs-site API reference update in
PRE_RELEASE_DOCS.md, and link the PR from the changelog entry.
@jasonsaayman jasonsaayman added the ai-assisted This PR was created with or in conjunction with AI label Nov 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread PRE_RELEASE_DOCS.md Resolved
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@jasonsaayman
jasonsaayman merged commit 6f5950a into axios:v1.x Nov 2, 2026
markharding pushed a commit to futo-org/Harbor that referenced this pull request Nov 17, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [axios](https://axios-http.com) ([source](https://github.com/axios/axios)) | [`1.21.0` → `1.21.1`](https://renovatebot.com/diffs/npm/axios/1.21.0/1.21.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/axios/1.21.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/axios/1.21.0/1.21.1?slim=true) |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/2097) for more information.

---

### Release Notes

<details>
<summary>axios/axios (axios)</summary>

### [`v1.21.1`](https://github.com/axios/axios/releases/tag/v1.21.1)

[Compare Source](axios/axios@v1.21.0...v1.21.1)

#### v1.21.1 — November 9, 2026

This release raises the minimum `follow-redirects` version to fix a published CVE, fixes a Next.js prerendering failure caused by the response duration timer, corrects the `getAdapter` typings, and includes documentation corrections, new test coverage, CI runner changes and dependency updates.

#### 🔒 Security Fixes

- **follow-redirects:** Raised the `follow-redirects` range from `^1.16.0` to `^1.16.2` to fix CVE-2026-116689 (GHSA-mrwp-f3q8-3g9p). In the vulnerable versions, `sensitiveHeaders` arrays from another realm were ignored and custom credentials could follow redirects. Only the Node.js HTTP adapter is affected, and there are no API changes. (**[#&#8203;11410](axios/axios#11410)

#### 🐛 Bug Fixes

- **Response Duration:** `dispatchRequest` now measures `response.duration` with `performance.now()` and uses `Date.now()` only when `performance.now()` isn't available. In v1.21.0, any axios request from a Server Component failed Next.js production builds with Cache Components (`cacheComponents: true`), because Next.js rejects `Date.now()` while prerendering. The duration is still a whole number of milliseconds, and system clock changes no longer affect it. (**[#&#8203;11411](axios/axios#11411)
- **TypeScript:** `getAdapter` now accepts an optional `config?: AxiosRequestConfig` in `index.d.ts` and `index.d.cts`, matching what it does at runtime. You can now call `getAdapter('fetch', { env: { fetch: myFetch } })` without a cast. (**[#&#8203;11404](axios/axios#11404)

#### 🔧 Maintenance & Chores

- **Documentation Corrections:** Brought the README and docs site in line with how axios actually behaves:

  - `transformRequest` runs for every method, and transformers receive `(data, headers, status)`.
  - `responseType` and `Content-Type` have no default value.
  - `AxiosHeaders#get` and `#normalize` are described correctly.
  - Errors should be identified with `axios.isAxiosError()`, not by `name`.
  - The error tables now list `ECONNREFUSED` and `ERR_FORM_DATA_DEPTH_EXCEEDED`, and note that FormData parsing has a fixed depth limit that `maxDepth` doesn't change.
  - New notes cover what `redact` doesn't scan, which adapters enforce `maxContentLength` / `maxBodyLength`, and how `formToJSON()` handles field name collisions.

  (**[#&#8203;11374](axios/axios#11374, **[#&#8203;11373](axios/axios#11373, **[#&#8203;11389](axios/axios#11389, **[#&#8203;11419](axios/axios#11419, **[#&#8203;11429](axios/axios#11429, **[#&#8203;11430](axios/axios#11430)
- **Docs Site:** Added a Partners page, a shared card design for sponsors and partners, a Namespace sponsor badge, and a blog whose first post announces HeroDevs Never-Ending Support for Axios v0. Also applied the v1.20.0/v1.21.0 release notes to the docs, and fixed internal links in the es, fr and zh translations so they keep their locale prefix. (**[#&#8203;11390](axios/axios#11390, **[#&#8203;11399](axios/axios#11399, **[#&#8203;11400](axios/axios#11400, **[#&#8203;11412](axios/axios#11412, **[#&#8203;11401](axios/axios#11401)
- **Test Coverage:** Added cancellation tests across the HTTP, fetch and XHR adapters. They cover `AbortSignal`, `CancelToken`, cancelling while a request interceptor is pending, and timeout precedence. Also added tests for `no_proxy` edge cases in `shouldBypassProxy`, such as internationalized domain names, malformed CIDR and IPv4 entries, and port-qualified entries. Neither changes runtime behavior. (**[#&#8203;11376](axios/axios#11376, **[#&#8203;11431](axios/axios#11431)
- **CI:** GitHub Actions jobs now run on Namespace runners. The npm publish job stays on GitHub-hosted runners, because npm provenance and trusted publishing (OIDC) only work there. (**[#&#8203;11396](axios/axios#11396)
- **Dependencies:** Updated development and tooling dependencies, including `vitest` and `@vitest/*` (to 5.x at the root), `typescript` (7.x at the root), `vite`, `rollup`, `eslint`, `playwright`, `@commitlint/*`, `@rollup/plugin-alias`, `@rollup/plugin-terser`, `body-parser`, `multer`, `serialize-javascript`, `fast-uri`, `qs`, `zizmorcore/zizmor-action`, and `follow-redirects` in `/docs`. (**[#&#8203;11383](axios/axios#11383, **[#&#8203;11375](axios/axios#11375, **[#&#8203;11372](axios/axios#11372, **[#&#8203;11345](axios/axios#11345, **[#&#8203;11392](axios/axios#11392, **[#&#8203;11387](axios/axios#11387, **[#&#8203;11386](axios/axios#11386, **[#&#8203;11385](axios/axios#11385, **[#&#8203;11391](axios/axios#11391, **[#&#8203;11388](axios/axios#11388, **[#&#8203;11395](axios/axios#11395, **[#&#8203;11421](axios/axios#11421, **[#&#8203;11422](axios/axios#11422, **[#&#8203;11426](axios/axios#11426)
- **Release:** Prepared the 1.21.1 release. (**[#&#8203;11435](axios/axios#11435)

#### 🌟 New Contributors

We are thrilled to welcome our new contributors. Thank you for helping improve axios:

- **[@&#8203;Ghoscro](https://github.com/Ghoscro)** (**[#&#8203;11374](axios/axios#11374)
- **[@&#8203;pei711](https://github.com/pei711)** (**[#&#8203;11373](axios/axios#11373)
- **[@&#8203;ivanhapaz](https://github.com/ivanhapaz)** (**[#&#8203;11399](axios/axios#11399)
- **[@&#8203;aelmanaa](https://github.com/aelmanaa)** (**[#&#8203;11404](axios/axios#11404)
- **[@&#8203;Aryapatel-007](https://github.com/Aryapatel-007)** (**[#&#8203;11429](axios/axios#11429, **[#&#8203;11430](axios/axios#11430)
- **[@&#8203;umair-ghafoor-ai](https://github.com/umair-ghafoor-ai)** (**[#&#8203;11376](axios/axios#11376)
- **[@&#8203;yxshee](https://github.com/yxshee)** (**[#&#8203;11389](axios/axios#11389)
- **[@&#8203;malinele](https://github.com/malinele)** (**[#&#8203;11401](axios/axios#11401)
- **[@&#8203;AnantDuhan](https://github.com/AnantDuhan)** (**[#&#8203;11431](axios/axios#11431)

[Full Changelog](axios/axios@v1.21.0...v1.21.1)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMjcuNCIsInVwZGF0ZWRJblZlciI6IjQ0LjIyNy40IiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/2336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted This PR was created with or in conjunction with AI commit::fix The PR is related to a bugfix v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getAdapter typings omit the config argument

3 participants