-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
defaults.headers.common is of type string instead of Record<string, string> #4108
Copy link
Copy link
Closed
Closed
Copy link
Description
Describe the issue
Headers are typed as Record<string, string>. This includes axios.defaults.headers, which is configured as:
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_TOKENExpected 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels