mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(types): allow to specify partial default headers for instance creation (#4185)
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Vendored
+5
-1
@@ -137,6 +137,10 @@ export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'hea
|
|||||||
headers: HeadersDefaults;
|
headers: HeadersDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||||
|
headers?: AxiosRequestHeaders | Partial<HeadersDefaults>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AxiosResponse<T = any, D = any> {
|
export interface AxiosResponse<T = any, D = any> {
|
||||||
data: T;
|
data: T;
|
||||||
status: number;
|
status: number;
|
||||||
@@ -254,7 +258,7 @@ export interface GenericFormData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AxiosStatic extends AxiosInstance {
|
export interface AxiosStatic extends AxiosInstance {
|
||||||
create(config?: AxiosRequestConfig): AxiosInstance;
|
create(config?: CreateAxiosDefaults): AxiosInstance;
|
||||||
Cancel: CancelStatic;
|
Cancel: CancelStatic;
|
||||||
CancelToken: CancelTokenStatic;
|
CancelToken: CancelTokenStatic;
|
||||||
Axios: typeof Axios;
|
Axios: typeof Axios;
|
||||||
|
|||||||
@@ -263,6 +263,11 @@ instance1.defaults.headers.common['Authorization'] = 'token';
|
|||||||
instance1.defaults.headers.post['X-FOO'] = 'bar';
|
instance1.defaults.headers.post['X-FOO'] = 'bar';
|
||||||
instance1.defaults.timeout = 2500;
|
instance1.defaults.timeout = 2500;
|
||||||
|
|
||||||
|
// axios create defaults
|
||||||
|
|
||||||
|
axios.create({ headers: { foo: 'bar' } });
|
||||||
|
axios.create({ headers: { common: { foo: 'bar' } } });
|
||||||
|
|
||||||
// Interceptors
|
// Interceptors
|
||||||
|
|
||||||
const requestInterceptorId: number = axios.interceptors.request.use(
|
const requestInterceptorId: number = axios.interceptors.request.use(
|
||||||
|
|||||||
Reference in New Issue
Block a user