fix(types): constrain AxiosHeaders index values by pupuking723 · Pull Request #11005 · axios/axios · GitHub
Skip to content

fix(types): constrain AxiosHeaders index values#11005

Open
pupuking723 wants to merge 2 commits into
axios:v1.xfrom
pupuking723:fix/headers-indexer-type
Open

fix(types): constrain AxiosHeaders index values#11005
pupuking723 wants to merge 2 commits into
axios:v1.xfrom
pupuking723:fix/headers-indexer-type

Conversation

@pupuking723

@pupuking723 pupuking723 commented Jun 12, 2026

Copy link
Copy Markdown

Summary

Constrain the AxiosHeaders string index signature so dynamic header assignments must be Axios header values instead of any.

🏄 I used an AI coding assistant while preparing this PR, and manually reviewed the issue, implementation, tests, and verification output before submitting.

Linked issue

Fixes #7487

Changes

  • Change the AxiosHeaders index signature in index.d.ts and index.d.cts from any to AxiosHeaderValue or callable class members.
  • Add ESM and CJS typing coverage that rejects Promise and arbitrary object header assignments while preserving valid dynamic header values.

Checklist

  • Tests added or updated
  • Docs/types updated if public API changed (index.d.ts and index.d.cts)
  • No breaking changes

Verification:

  • npm run test:module:esm -- tests/typings.module.test.js
  • ./node_modules/.bin/mocha --timeout 10000 tests/typings.module.test.cjs --grep "type-checks commonjs axios typings"
  • npx prettier --check index.d.ts index.d.cts tests/module/esm/tests/helpers/esm-index.ts tests/module/cjs/tests/helpers/cjs-typing.ts
  • git diff --check
  • npm run build

Note: Full local module tests require the CI tarball install step. Running them without installing the packed axios tarball into tests/module/* fails at runtime with Cannot find module 'axios', while the targeted typing tests above pass.


Summary by cubic

Tightens AxiosHeaders index signature to only allow AxiosHeaderValue, undefined, or callable members. Blocks Promises and objects to improve type safety in both ESM and CJS.

Description

Docs

Update /docs/ to:

  • List allowed dynamic header values: string, number, boolean, null, undefined.
  • Show examples for setting/removing headers; note Promises/objects are rejected.

Testing

  • Updated ESM and CJS typing tests to:
    • Accept null and undefined values.
    • Reject Promise and object assignments, including inside interceptors.
  • No runtime changes; type-only verification.

Semantic version impact

Patch: type definitions only, no runtime API changes.

Written for commit 11dfa88. Summary will update on new commits.

Review in cubic

@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.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Comment thread index.d.cts Outdated
@jasonsaayman jasonsaayman added commit::fix The PR is related to a bugfix status::changes-requested A reviewer requested changes to the PR labels Jun 18, 2026
@pupuking723 pupuking723 force-pushed the fix/headers-indexer-type branch from 89d08fd to dd66afa Compare June 22, 2026 08:32
@pupuking723 pupuking723 force-pushed the fix/headers-indexer-type branch from dd66afa to 11dfa88 Compare June 24, 2026 07:21
@pupuking723

Copy link
Copy Markdown
Author

@jasonsaayman jasonsaayman added type::breaking The PR introduces breaking changes status::blocked This PR or issue is deemed to be blocked labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix status::blocked This PR or issue is deemed to be blocked status::changes-requested A reviewer requested changes to the PR type::breaking The PR introduces breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typings bug (not type safety): class field type of AxiosHeaders => any

2 participants