mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
fix(types): renamed RawAxiosRequestConfig back to AxiosRequestConfig; (#5486)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import axios = require('axios');
|
||||
|
||||
const config: axios.RawAxiosRequestConfig = {
|
||||
const config: axios.AxiosRequestConfig = {
|
||||
url: '/user',
|
||||
method: 'get',
|
||||
baseURL: 'https://api.example.com/',
|
||||
@@ -38,11 +38,11 @@ const config: axios.RawAxiosRequestConfig = {
|
||||
cancelToken: new axios.CancelToken((cancel: axios.Canceler) => {})
|
||||
};
|
||||
|
||||
const nullValidateStatusConfig: axios.RawAxiosRequestConfig = {
|
||||
const nullValidateStatusConfig: axios.AxiosRequestConfig = {
|
||||
validateStatus: null
|
||||
};
|
||||
|
||||
const undefinedValidateStatusConfig: axios.RawAxiosRequestConfig = {
|
||||
const undefinedValidateStatusConfig: axios.AxiosRequestConfig = {
|
||||
validateStatus: undefined
|
||||
};
|
||||
|
||||
@@ -276,19 +276,19 @@ axios.create({
|
||||
// Interceptors
|
||||
|
||||
const requestInterceptorId: number = axios.interceptors.request.use(
|
||||
(config: axios.AxiosRequestConfig) => config,
|
||||
(config: axios.InternalAxiosRequestConfig) => config,
|
||||
(error: any) => Promise.reject(error)
|
||||
);
|
||||
|
||||
axios.interceptors.request.eject(requestInterceptorId);
|
||||
|
||||
axios.interceptors.request.use(
|
||||
(config: axios.AxiosRequestConfig) => Promise.resolve(config),
|
||||
(config: axios.InternalAxiosRequestConfig) => Promise.resolve(config),
|
||||
(error: any) => Promise.reject(error)
|
||||
);
|
||||
|
||||
axios.interceptors.request.use((config: axios.AxiosRequestConfig) => config);
|
||||
axios.interceptors.request.use((config: axios.AxiosRequestConfig) => Promise.resolve(config));
|
||||
axios.interceptors.request.use((config: axios.InternalAxiosRequestConfig) => config);
|
||||
axios.interceptors.request.use((config: axios.InternalAxiosRequestConfig) => Promise.resolve(config));
|
||||
|
||||
const responseInterceptorId: number = axios.interceptors.response.use(
|
||||
(response: axios.AxiosResponse) => response,
|
||||
@@ -302,6 +302,13 @@ axios.interceptors.response.use(
|
||||
(error: any) => Promise.reject(error)
|
||||
);
|
||||
|
||||
axios.interceptors.request.use(req => {
|
||||
// https://github.com/axios/axios/issues/5415
|
||||
req.headers.set('foo', 'bar');
|
||||
req.headers['Content-Type'] = 123;
|
||||
return req;
|
||||
});
|
||||
|
||||
const voidRequestInterceptorId = axios.interceptors.request.use(
|
||||
// @ts-expect-error -- Must return an axios.AxiosRequestConfig (or throw)
|
||||
(_response) => {},
|
||||
@@ -323,7 +330,7 @@ axios.interceptors.response.clear();
|
||||
|
||||
// Adapters
|
||||
|
||||
const adapter: axios.AxiosAdapter = (config: axios.AxiosRequestConfig) => {
|
||||
const adapter: axios.AxiosAdapter = (config: axios.InternalAxiosRequestConfig) => {
|
||||
const response: axios.AxiosResponse = {
|
||||
data: { foo: 'bar' },
|
||||
status: 200,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios, {
|
||||
RawAxiosRequestConfig,
|
||||
InternalAxiosRequestConfig,
|
||||
AxiosRequestConfig,
|
||||
AxiosHeaders,
|
||||
AxiosRequestHeaders,
|
||||
@@ -22,7 +22,7 @@ import axios, {
|
||||
spread
|
||||
} from 'axios';
|
||||
|
||||
const config: RawAxiosRequestConfig = {
|
||||
const config: AxiosRequestConfig = {
|
||||
url: '/user',
|
||||
method: 'get',
|
||||
baseURL: 'https://api.example.com/',
|
||||
@@ -60,11 +60,11 @@ const config: RawAxiosRequestConfig = {
|
||||
cancelToken: new axios.CancelToken((cancel: Canceler) => {})
|
||||
};
|
||||
|
||||
const nullValidateStatusConfig: RawAxiosRequestConfig = {
|
||||
const nullValidateStatusConfig: AxiosRequestConfig = {
|
||||
validateStatus: null
|
||||
};
|
||||
|
||||
const undefinedValidateStatusConfig: RawAxiosRequestConfig = {
|
||||
const undefinedValidateStatusConfig: AxiosRequestConfig = {
|
||||
validateStatus: undefined
|
||||
};
|
||||
|
||||
@@ -515,7 +515,7 @@ axios.get('/user', {
|
||||
|
||||
// issue #5034
|
||||
|
||||
function getRequestConfig1(options: RawAxiosRequestConfig): RawAxiosRequestConfig {
|
||||
function getRequestConfig1(options: AxiosRequestConfig): AxiosRequestConfig {
|
||||
return {
|
||||
...options,
|
||||
headers: {
|
||||
@@ -525,7 +525,7 @@ function getRequestConfig1(options: RawAxiosRequestConfig): RawAxiosRequestConfi
|
||||
};
|
||||
}
|
||||
|
||||
function getRequestConfig2(options: RawAxiosRequestConfig): RawAxiosRequestConfig {
|
||||
function getRequestConfig2(options: AxiosRequestConfig): AxiosRequestConfig {
|
||||
return {
|
||||
...options,
|
||||
headers: {
|
||||
@@ -609,7 +609,7 @@ for (const [header, value] of headers) {
|
||||
config.headers.foo = "1";
|
||||
config.headers.set('bar', '2');
|
||||
config.headers.set({myHeader: "myValue"})
|
||||
config.headers = new axios.AxiosHeaders({myHeader: "myValue"});
|
||||
config.headers = new AxiosHeaders({myHeader: "myValue"});
|
||||
config.headers = {...config.headers} as AxiosRequestHeaders;
|
||||
return config;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user