Skip to content

Incomplete typings for AxiosRequestHeaders #4335

@turisap

Description

@turisap

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

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