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
  • Loading branch information
lukashroch committed May 4, 2022
1 parent 384b7e6 commit 2d1e100
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 @@ -248,7 +252,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 @@ -261,6 +261,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 2d1e100

Please sign in to comment.