-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
AxiosRequestHeaders type breaks from 0.21.4 to 0.22.0 #4193
Copy link
Copy link
Closed
Description
Describe the bug
The type has changed and now I am getting linting errors on a working code.
I get Element implicitly has an 'any' type because index expression is not of type 'number'.ts(7015) error when I try to access the headers by their name on a AxiosRequestHeaders object.
For example accessing a common header in transfomRequest where the content of headers is:

If I try to access the common Accept header key, then I will get the above error.
I think the issue is at:
Line 3 in 1025d12
| export type AxiosRequestHeaders = Record<string, string>; |
The type should be:
export type AxiosRequestHeaders = Record<string, Record<string, string>>; Possibly the AxiosResponseHeaders has the same issue.
To Reproduce
import axios from 'axios'
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone',
},
transformRequest: (_, headers) => {
if(headers)
delete headers.common['Accept'] //Error occurs here
},
})
.then(function (response) {
console.log(response)
})
.catch(function (error) {
console.log(error)
})Expected behavior
Expected to not raise an error there
Environment
- Axios 0.23.0
- TypeScript 4.4.4
Additional context/Screenshots
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
