question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incomplete typings for AxiosRequestHeaders

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
eridrcommented, May 13, 2022

This is still an issue. 🦺 Hurts to // @ts-ignore it everywhere…

4reactions
kherockcommented, Mar 15, 2022

I would also appreciate the linked PR being merged!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found