Skip to content

defaults.headers.common is of type string instead of Record<string, string> #4108

@askielboe

Description

@askielboe

Describe the issue

Headers are typed as Record<string, string>. This includes axios.defaults.headers, which is configured as:

axios/lib/defaults.js

Lines 119 to 123 in 76f09af

headers: {
common: {
'Accept': 'application/json, text/plain, */*'
}
}

This seems incompatible with headers being of type Record<string, string>.

Example Code

The following line produces a TypeScript error beacuse headers.commons is of type string: "Element implicitly has an 'any' type because index expression is not of type 'number'.ts(7015)".

axios.defaults.headers.common['Authorization'] = AUTH_TOKEN

Expected behavior, if applicable

I expect to be able to configure default headers without TypeScript errors. Using the code examples from the Axios documentation, I would exspect axios.defaults.headers.common to be of type Record<string, string> not of type string.

Environment

  • Axios Version 0.22.0
  • Adapter N/A
  • Browser N/A
  • Browser Version N/A
  • Node.js Version 15.14.0
  • OS: Ubuntu 21.04
  • Additional Library Versions TypeScript 4.4.3

Additional context/Screenshots

Add any other context about the problem here. If applicable, add screenshots to help explain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions