Skip to content

Commit

Permalink
fix(types): allow to specify partial default headers for instance cre…
Browse files Browse the repository at this point in the history
…ation (#4185)

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
lukashroch and jasonsaayman committed May 9, 2022
1 parent 356b166 commit ac96144
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.d.ts
Expand Up @@ -137,6 +137,10 @@ export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'hea
headers: HeadersDefaults;
}

export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
headers?: AxiosRequestHeaders | Partial<HeadersDefaults>;
}

export interface AxiosResponse<T = any, D = any> {
data: T;
status: number;
Expand Down Expand Up @@ -254,7 +258,7 @@ export interface GenericFormData {
}

export interface AxiosStatic extends AxiosInstance {
create(config?: AxiosRequestConfig): AxiosInstance;
create(config?: CreateAxiosDefaults): AxiosInstance;
Cancel: CancelStatic;
CancelToken: CancelTokenStatic;
Axios: typeof Axios;
Expand Down
5 changes: 5 additions & 0 deletions test/typescript/axios.ts
Expand Up @@ -263,6 +263,11 @@ instance1.defaults.headers.common['Authorization'] = 'token';
instance1.defaults.headers.post['X-FOO'] = 'bar';
instance1.defaults.timeout = 2500;

// axios create defaults

axios.create({ headers: { foo: 'bar' } });
axios.create({ headers: { common: { foo: 'bar' } } });

// Interceptors

const requestInterceptorId: number = axios.interceptors.request.use(
Expand Down

0 comments on commit ac96144

Please sign in to comment.