Skip to content

Commit

Permalink
fix: Type of header in AxiosRequestConfig is incorrect
Browse files Browse the repository at this point in the history
The type of the headers property in Axios.create config has not support
headers for specific requests method (or common).

Closes axios#4911
  • Loading branch information
WillianAgostini committed Aug 21, 2022
1 parent 66d4780 commit abca2b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.d.ts
@@ -1,5 +1,11 @@
// TypeScript Version: 4.1
type AxiosHeaders = Record<string, string | string[] | number | boolean>;
type JSONValue = string | string[] | number | boolean;

interface JSONObject {
[x: string]: JSONValue;
}

type AxiosHeaders = Record<string, JSONValue | JSONObject>;

type MethodsHeaders = {
[Key in Method as Lowercase<Key>]: AxiosHeaders;
Expand Down
4 changes: 4 additions & 0 deletions test/typescript/axios.ts
Expand Up @@ -162,6 +162,10 @@ axios.post<User>('/user', { name: 'foo', id: 1 }, { headers: { 'X-FOO': 'bar' }
.then(handleUserResponse)
.catch(handleError);

axios.post<User>('/user', { name: 'foo', id: 1 }, { headers: { get: { 'X-FOO': 'bar' }} })
.then(handleUserResponse)
.catch(handleError);

axios.put<User>('/user', { name: 'foo', id: 1 })
.then(handleUserResponse)
.catch(handleError);
Expand Down

0 comments on commit abca2b6

Please sign in to comment.