Skip to content

AxiosHeaders class type definitions expose a missing setAuthorization method #5501

@vovaklimov

Description

@vovaklimov

Describe the bug

I'm trying to create a basic request interceptor to set Authorization header. According to axios type definitions, I can use config.headers.setAuthorization method in my interceptor.

image

image

TypeScript compiles my source code correctly, but it fails to run, throwing a TypeError

image

To Reproduce

https://runkit.com/embed/70jjrl0otnq7

Code snippet

import axios from 'axios';

axios.interceptors.request.use((config) => {
  config.headers.setAuthorization('Bearer 🐻');

  return config;
});

await axios.get('https://www.google.com')

Expected behavior

I expect config.headers.setAuthorization() to correctly set Authorization http header for HTTP requests in runtime according to type definitions.

Axios Version

1.2.5

Adapter Version

HTTP

Browser

No response

Browser Version

No response

Node.js Version

18.13.0

OS

Fedora 37

Additional Library Versions

"@types/node": "^18.11.18"
"typescript": "^4.9.4"

Additional context/Screenshots

No response

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