Types prevent adding new values to headers

See original GitHub issue

Describe the bug

Types prevent adding new values to headers

To Reproduce

function getRequestConfig(options: AxiosRequestConfig): AxiosRequestConfig {
  return {
    ...options,
    headers: {
      ...options.headers,
      Authorization: `Bearer ...`,
    },
  };
}
TS2322: Type '{ Authorization: string; get?: AxiosHeaders | undefined; delete?: AxiosHeaders | undefined; head?: AxiosHeaders | undefined; options?: AxiosHeaders | undefined; ... 6 more ...; common?: AxiosHeaders | undefined; }' is not assignable to type 'Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>'.
   Property 'get' is incompatible with index signature.
     Type 'AxiosHeaders' is not assignable to type 'AxiosHeaderValue | undefined'. 

Expected behavior

Everything is working

Environment

  • Axios Version 1.0.0

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:9
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
lakessydecommented, Dec 1, 2022

Type ‘Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders> | undefined’ is not assignable to type ‘AxiosRequestHeaders | undefined’. Type ‘Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>’ is not assignable to type ‘AxiosRequestHeaders’. Type ‘Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>’ is missing the following properties from type ‘AxiosHeaders’: set, has, clear, normalize, and 17 more.

Axios version :1.2.0

is there a fix to this

1reaction
ndjerroucommented, Nov 21, 2022

I got this :

Error: Type '{ Authorization: string; }' is not assignable to type 'Partial<HeadersDefaults> | Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders> | undefined'.

Axios : version 1.1.3

const client = axios.create({ baseURL: API_URL, timeout: 1000, headers: {Authorization: ``Bearer ${OAUTH_TOKEN}``}, });

what’s wrong ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content-Type - HTTP - MDN Web Docs - Mozilla
In requests, (such as POST or PUT ), the client tells the server what type of data is actually sent. Header type, Representation...
Read more >
Promote or demote rows and column headers (Power Query)
To open a query, locate one previously loaded from the Power Query Editor, select a cell in the data, and then select Query...
Read more >
Power Query: Avoiding naming column headers to avoid breaks
Here are the custom M functions I use: Create a list of column names : Table.ColumnNames(Source) Convert values into their type (e.g. date, ......
Read more >
Prevent pandas read_csv treating first row as header of ...
You want header=None the False gets type promoted to int into 0 see the docs emphasis mine: header : int or list of...
Read more >
HTTP security headers: An easy way to harden your web ...
The recommended way to prevent website certificate spoofing is to use the Expect-CT header to indicate that only new certificates added to ...
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