Incomplete typings for AxiosRequestHeaders
See original GitHub issueDescribe the bug
AxiosRequestHeaders
is currently only a Record
for primitives Record<string, string | number | boolean>
and, according to typing cannot have object as values. In reality, headers under keys can objects with other keys. A good example is from README:
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
To Reproduce
F.e. if we were to delete a header entry in transformRequest
we would get a typescript error Property 'Authorization' does not exist on type 'string'.
return axios({
method : 'get',
transformRequest: (data, headers) => {
delete headers?.common?.Authorization;
}
})
Expected behavior
To be able to access / delete headers under the whole list of keys common, post, etc
Environment
- Axios Version 0.24.0
- Adapter HTTP
Additional context/Screenshots
This is a typescript bug
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to typify axios request headers - Stack Overflow
I've created an interface Headers and used it to declare variable this._apiHeaders . Error text: The "Headers" type cannot be assigned to the...
Read more >reactjs input element loses focus after keystroke-Reactjs
React - Input loses focus after typing 1 char in dynamic form · Input element losing it's focus ... Removing incomplete data from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is still an issue. 🦺 Hurts to
// @ts-ignore
it everywhere…I would also appreciate the linked PR being merged!