Skip to content

Commit

Permalink
fix: [Types] Type of header in AxiosRequestConfig / for Axios.create …
Browse files Browse the repository at this point in the history
…is incorrect (#4927)

* test: Fail test to #4911

Type of header in AxiosRequestConfig / for Axios.create is incorrect

* fix: Type of header in AxiosRequestConfig is incorrect

Add new type for MethodsHeaders in AxiosRequestHeaders

Closes #4911

* refactor: Remove interface to add type #4927

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
WillianAgostini and jasonsaayman committed Sep 28, 2022
1 parent 80b546c commit 1e2679f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.d.ts
@@ -1,5 +1,7 @@
// TypeScript Version: 4.1
type AxiosHeaders = Record<string, string | string[] | number | boolean>;
type HeaderValue = string | string[] | number | boolean;

type AxiosHeaders = Record<string, HeaderValue | Record<Method & CommonHeaders, HeaderValue>>;

type MethodsHeaders = {
[Key in Method as Lowercase<Key>]: AxiosHeaders;
Expand Down
4 changes: 4 additions & 0 deletions test/typescript/axios.ts
Expand Up @@ -204,6 +204,10 @@ axios.post<Partial<UserCreationDef>, string>('/user', { name: 'foo' }, { headers
.then(handleStringResponse)
.catch(handleError);

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

axios.put<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
.then(handleStringResponse)
.catch(handleError);
Expand Down

0 comments on commit 1e2679f

Please sign in to comment.