From 08119634a22f1d5b19f5c9ea0adccb6d3eebc3bc Mon Sep 17 00:00:00 2001 From: Dmitriy Mozgovoy Date: Fri, 6 Jan 2023 02:02:08 +0200 Subject: [PATCH] fix(types): fixed AxiosRequestConfig header interface by refactoring it to RawAxiosRequestConfig; (#5420) --- index.d.cts | 42 ++--- index.d.ts | 42 ++--- test/module/test.js | 117 +++++++------- test/module/typings/cjs/index.ts | 6 +- test/module/typings/esm/index.ts | 264 ++++++++++++++++--------------- 5 files changed, 245 insertions(+), 226 deletions(-) diff --git a/index.d.cts b/index.d.cts index 844cda67b7..182532a886 100644 --- a/index.d.cts +++ b/index.d.cts @@ -103,24 +103,24 @@ declare class CanceledError extends AxiosError { } declare class Axios { - constructor(config?: axios.AxiosRequestConfig); + constructor(config?: axios.RawAxiosRequestConfig); defaults: axios.AxiosDefaults; interceptors: { request: axios.AxiosInterceptorManager; response: axios.AxiosInterceptorManager; }; - getUri(config?: axios.AxiosRequestConfig): string; - request, D = any>(config: axios.AxiosRequestConfig): Promise; - get, D = any>(url: string, config?: axios.AxiosRequestConfig): Promise; - delete, D = any>(url: string, config?: axios.AxiosRequestConfig): Promise; - head, D = any>(url: string, config?: axios.AxiosRequestConfig): Promise; - options, D = any>(url: string, config?: axios.AxiosRequestConfig): Promise; - post, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig): Promise; - put, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig): Promise; - patch, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig): Promise; - postForm, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig): Promise; - putForm, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig): Promise; - patchForm, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig): Promise; + getUri(config?: axios.RawAxiosRequestConfig): string; + request, D = any>(config: axios.RawAxiosRequestConfig): Promise; + get, D = any>(url: string, config?: axios.RawAxiosRequestConfig): Promise; + delete, D = any>(url: string, config?: axios.RawAxiosRequestConfig): Promise; + head, D = any>(url: string, config?: axios.RawAxiosRequestConfig): Promise; + options, D = any>(url: string, config?: axios.RawAxiosRequestConfig): Promise; + post, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig): Promise; + put, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig): Promise; + patch, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig): Promise; + postForm, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig): Promise; + putForm, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig): Promise; + patchForm, D = any>(url: string, data?: D, config?: axios.RawAxiosRequestConfig): Promise; } declare enum HttpStatusCode { @@ -342,7 +342,7 @@ declare namespace axios { type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName; - interface AxiosRequestConfig { + interface RawAxiosRequestConfig { url?: string; method?: Method | string; baseURL?: string; @@ -384,6 +384,10 @@ declare namespace axios { formSerializer?: FormSerializerOptions; } + interface AxiosRequestConfig extends RawAxiosRequestConfig { + headers: AxiosRequestHeaders; + } + interface HeadersDefaults { common: RawAxiosRequestHeaders; delete: RawAxiosRequestHeaders; @@ -398,11 +402,11 @@ declare namespace axios { unlink?: RawAxiosRequestHeaders; } - interface AxiosDefaults extends Omit, 'headers'> { + interface AxiosDefaults extends Omit, 'headers'> { headers: HeadersDefaults; } - interface CreateAxiosDefaults extends Omit, 'headers'> { + interface CreateAxiosDefaults extends Omit, 'headers'> { headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial; } @@ -426,7 +430,7 @@ declare namespace axios { } interface Canceler { - (message?: string, config?: AxiosRequestConfig, request?: any): void; + (message?: string, config?: RawAxiosRequestConfig, request?: any): void; } interface CancelTokenStatic { @@ -457,8 +461,8 @@ declare namespace axios { } interface AxiosInstance extends Axios { - , D = any>(config: AxiosRequestConfig): Promise; - , D = any>(url: string, config?: AxiosRequestConfig): Promise; + , D = any>(config: RawAxiosRequestConfig): Promise; + , D = any>(url: string, config?: RawAxiosRequestConfig): Promise; defaults: Omit & { headers: HeadersDefaults & { diff --git a/index.d.ts b/index.d.ts index 35d50e3c1f..5b2b6141a0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -283,7 +283,7 @@ type AxiosAdapterName = 'xhr' | 'http' | string; type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName; -export interface AxiosRequestConfig { +export interface RawAxiosRequestConfig { url?: string; method?: Method | string; baseURL?: string; @@ -325,6 +325,10 @@ export interface AxiosRequestConfig { formSerializer?: FormSerializerOptions; } +export interface AxiosRequestConfig extends RawAxiosRequestConfig { + headers: AxiosRequestHeaders; +} + export interface HeadersDefaults { common: RawAxiosRequestHeaders; delete: RawAxiosRequestHeaders; @@ -339,11 +343,11 @@ export interface HeadersDefaults { unlink?: RawAxiosRequestHeaders; } -export interface AxiosDefaults extends Omit, 'headers'> { +export interface AxiosDefaults extends Omit, 'headers'> { headers: HeadersDefaults; } -export interface CreateAxiosDefaults extends Omit, 'headers'> { +export interface CreateAxiosDefaults extends Omit, 'headers'> { headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial; } @@ -409,7 +413,7 @@ export interface Cancel { } export interface Canceler { - (message?: string, config?: AxiosRequestConfig, request?: any): void; + (message?: string, config?: RawAxiosRequestConfig, request?: any): void; } export interface CancelTokenStatic { @@ -440,29 +444,29 @@ export interface AxiosInterceptorManager { } export class Axios { - constructor(config?: AxiosRequestConfig); + constructor(config?: RawAxiosRequestConfig); defaults: AxiosDefaults; interceptors: { request: AxiosInterceptorManager; response: AxiosInterceptorManager; }; - getUri(config?: AxiosRequestConfig): string; - request, D = any>(config: AxiosRequestConfig): Promise; - get, D = any>(url: string, config?: AxiosRequestConfig): Promise; - delete, D = any>(url: string, config?: AxiosRequestConfig): Promise; - head, D = any>(url: string, config?: AxiosRequestConfig): Promise; - options, D = any>(url: string, config?: AxiosRequestConfig): Promise; - post, D = any>(url: string, data?: D, config?: AxiosRequestConfig): Promise; - put, D = any>(url: string, data?: D, config?: AxiosRequestConfig): Promise; - patch, D = any>(url: string, data?: D, config?: AxiosRequestConfig): Promise; - postForm, D = any>(url: string, data?: D, config?: AxiosRequestConfig): Promise; - putForm, D = any>(url: string, data?: D, config?: AxiosRequestConfig): Promise; - patchForm, D = any>(url: string, data?: D, config?: AxiosRequestConfig): Promise; + getUri(config?: RawAxiosRequestConfig): string; + request, D = any>(config: RawAxiosRequestConfig): Promise; + get, D = any>(url: string, config?: RawAxiosRequestConfig): Promise; + delete, D = any>(url: string, config?: RawAxiosRequestConfig): Promise; + head, D = any>(url: string, config?: RawAxiosRequestConfig): Promise; + options, D = any>(url: string, config?: RawAxiosRequestConfig): Promise; + post, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig): Promise; + put, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig): Promise; + patch, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig): Promise; + postForm, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig): Promise; + putForm, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig): Promise; + patchForm, D = any>(url: string, data?: D, config?: RawAxiosRequestConfig): Promise; } export interface AxiosInstance extends Axios { - , D = any>(config: AxiosRequestConfig): Promise; - , D = any>(url: string, config?: AxiosRequestConfig): Promise; + , D = any>(config: RawAxiosRequestConfig): Promise; + , D = any>(url: string, config?: RawAxiosRequestConfig): Promise; defaults: Omit & { headers: HeadersDefaults & { diff --git a/test/module/test.js b/test/module/test.js index 3410ca2a88..c4e3d1ebf2 100644 --- a/test/module/test.js +++ b/test/module/test.js @@ -58,90 +58,93 @@ describe('module', function () { await remove(BACKUP_PATH); }); - it('should have consistent ESM export', function () { - const namedExport = {}; - const factoryExport = {}; - - Object.entries(axiosFactory).forEach(([key, value]) => { - if(!utils.hasOwnProp(Axios, key) && !(key in instance) && ignoreList.indexOf(key) === -1) { - factoryExport[key] = value; - } - }); + describe('export', function () { - Object.entries(axios).forEach(([key, value]) => { - key!=='default' && ignoreList.indexOf(key) === -1 && (namedExport[key] = value); - }); + it('should have consistent ESM export', function () { + const namedExport = {}; + const factoryExport = {}; - assert.deepStrictEqual(namedExport, factoryExport); - }); + Object.entries(axiosFactory).forEach(([key, value]) => { + if (!utils.hasOwnProp(Axios, key) && !(key in instance) && ignoreList.indexOf(key) === -1) { + factoryExport[key] = value; + } + }); - describe('CommonJS', ()=> { - const pkgPath = path.join(__dirname, './cjs'); + Object.entries(axios).forEach(([key, value]) => { + key !== 'default' && ignoreList.indexOf(key) === -1 && (namedExport[key] = value); + }); - after(async ()=> { - await remove(path.join(pkgPath, './node_modules')); + assert.deepStrictEqual(namedExport, factoryExport); }); - it('should be able to be loaded with require', async function () { - this.timeout(30000); + describe('CommonJS', () => { + const pkgPath = path.join(__dirname, './cjs'); - await exec(`npm test --prefix ${pkgPath}`); - }); - }); + after(async () => { + await remove(path.join(pkgPath, './node_modules')); + }); - describe('ESM', ()=> { - const pkgPath = path.join(__dirname, './esm'); + it('should be able to be loaded with require', async function () { + this.timeout(30000); - after(async ()=> { - await remove(path.join(pkgPath, './node_modules')); + await exec(`npm test --prefix ${pkgPath}`); + }); }); - it('should be able to be loaded with import', async function () { - this.timeout(30000); + describe('ESM', () => { + const pkgPath = path.join(__dirname, './esm'); - await exec(`npm test --prefix ${pkgPath}`); - }); - }); + after(async () => { + await remove(path.join(pkgPath, './node_modules')); + }); - describe('TS', ()=> { - const pkgPath = path.join(__dirname, './ts'); + it('should be able to be loaded with import', async function () { + this.timeout(30000); - after(async ()=> { - await remove(path.join(pkgPath, './node_modules')); + await exec(`npm test --prefix ${pkgPath}`); + }); }); - it('should be able to be loaded with import', async function () { - this.timeout(30000); + describe('TS', () => { + const pkgPath = path.join(__dirname, './ts'); - await exec(`npm test --prefix ${pkgPath}`, {}); - }); - }); + after(async () => { + await remove(path.join(pkgPath, './node_modules')); + }); - describe('TS require(\'axios\')', ()=> { - const pkgPath = path.join(__dirname, './ts-require'); + it('should be able to be loaded with import', async function () { + this.timeout(30000); - after(async ()=> { - await remove(path.join(pkgPath, './node_modules')); + await exec(`npm test --prefix ${pkgPath}`, {}); + }); }); - it('should be able to be loaded with require', async function () { - this.timeout(30000); + describe('TS require(\'axios\')', () => { + const pkgPath = path.join(__dirname, './ts-require'); - await exec(`npm test --prefix ${pkgPath}`, {}); - }); - }); + after(async () => { + await remove(path.join(pkgPath, './node_modules')); + }); - describe('TS require(\'axios\').default', ()=> { - const pkgPath = path.join(__dirname, './ts-require-default'); + it('should be able to be loaded with require', async function () { + this.timeout(30000); - after(async ()=> { - await remove(path.join(pkgPath, './node_modules')); + await exec(`npm test --prefix ${pkgPath}`, {}); + }); }); - it('should be able to be loaded with require', async function () { - this.timeout(30000); + describe('TS require(\'axios\').default', () => { + const pkgPath = path.join(__dirname, './ts-require-default'); + + after(async () => { + await remove(path.join(pkgPath, './node_modules')); + }); + + it('should be able to be loaded with require', async function () { + this.timeout(30000); - await exec(`npm test --prefix ${pkgPath}`, {}); + await exec(`npm test --prefix ${pkgPath}`, {}); + }); }); }); diff --git a/test/module/typings/cjs/index.ts b/test/module/typings/cjs/index.ts index 95a3524e07..36b55d6a00 100644 --- a/test/module/typings/cjs/index.ts +++ b/test/module/typings/cjs/index.ts @@ -1,6 +1,6 @@ import axios = require('axios'); -const config: axios.AxiosRequestConfig = { +const config: axios.RawAxiosRequestConfig = { url: '/user', method: 'get', baseURL: 'https://api.example.com/', @@ -38,11 +38,11 @@ const config: axios.AxiosRequestConfig = { cancelToken: new axios.CancelToken((cancel: axios.Canceler) => {}) }; -const nullValidateStatusConfig: axios.AxiosRequestConfig = { +const nullValidateStatusConfig: axios.RawAxiosRequestConfig = { validateStatus: null }; -const undefinedValidateStatusConfig: axios.AxiosRequestConfig = { +const undefinedValidateStatusConfig: axios.RawAxiosRequestConfig = { validateStatus: undefined }; diff --git a/test/module/typings/esm/index.ts b/test/module/typings/esm/index.ts index ba2e439509..224ba213e8 100644 --- a/test/module/typings/esm/index.ts +++ b/test/module/typings/esm/index.ts @@ -1,4 +1,5 @@ import axios, { + RawAxiosRequestConfig, AxiosRequestConfig, AxiosHeaders, AxiosRequestHeaders, @@ -21,7 +22,7 @@ import axios, { spread } from 'axios'; -const config: AxiosRequestConfig = { +const config: RawAxiosRequestConfig = { url: '/user', method: 'get', baseURL: 'https://api.example.com/', @@ -59,11 +60,11 @@ const config: AxiosRequestConfig = { cancelToken: new axios.CancelToken((cancel: Canceler) => {}) }; -const nullValidateStatusConfig: AxiosRequestConfig = { +const nullValidateStatusConfig: RawAxiosRequestConfig = { validateStatus: null }; -const undefinedValidateStatusConfig: AxiosRequestConfig = { +const undefinedValidateStatusConfig: RawAxiosRequestConfig = { validateStatus: undefined }; @@ -86,48 +87,48 @@ const handleError = (error: AxiosError) => { }; axios(config) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.get('/user?id=12345') - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.get('/user', { params: { id: 12345 } }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.head('/user') - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.options('/user') - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.delete('/user') - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.post('/user', { foo: 'bar' }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.post('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.put('/user', { foo: 'bar' }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); axios.patch('/user', { foo: 'bar' }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); // Typed methods interface UserCreationDef { - name: string; + name: string; } interface User { @@ -138,49 +139,49 @@ interface User { // with default AxiosResponse result const handleUserResponse = (response: AxiosResponse) => { - console.log(response.data.id); - console.log(response.data.name); - console.log(response.status); - console.log(response.statusText); - console.log(response.headers); - console.log(response.config); + console.log(response.data.id); + console.log(response.data.name); + console.log(response.status); + console.log(response.statusText); + console.log(response.headers); + console.log(response.config); }; axios.get('/user?id=12345') - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.get('/user', { params: { id: 12345 } }) - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.head('/user') - .then(handleUserResponse) + .then(handleUserResponse) .catch(handleError); axios.options('/user') - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.delete('/user') - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.post('/user', { name: 'foo', id: 1 }) - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.post('/user', { name: 'foo', id: 1 }, { headers: { 'X-FOO': 'bar' } }) - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.put('/user', { name: 'foo', id: 1 }) - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); axios.patch('/user', { name: 'foo', id: 1 }) - .then(handleUserResponse) - .catch(handleError); + .then(handleUserResponse) + .catch(handleError); // (Typed methods) with custom response type @@ -189,47 +190,47 @@ const handleStringResponse = (response: string) => { }; axios.get('/user?id=12345') - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.get('/user', { params: { id: 12345 } }) - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.head('/user') - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.options('/user') - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.delete('/user') - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.post, string>('/user', { name: 'foo' }) - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.post, string>('/user', { name: 'foo' }, { headers: { 'X-FOO': 'bar' } }) - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.put, string>('/user', { name: 'foo' }) - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.patch, string>('/user', { name: 'foo' }) - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); axios.request({ method: 'get', url: '/user?id=12345' }) - .then(handleStringResponse) - .catch(handleError); + .then(handleStringResponse) + .catch(handleError); // Instances @@ -237,32 +238,32 @@ const instance1: AxiosInstance = axios.create(); const instance2: AxiosInstance = axios.create(config); instance1(config) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); instance1.request(config) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); instance1.get('/user?id=12345') - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); instance1.options('/user') - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); instance1.get('/user', { params: { id: 12345 } }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); instance1.post('/user', { foo: 'bar' }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); instance1.post('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } }) - .then(handleResponse) - .catch(handleError); + .then(handleResponse) + .catch(handleError); // Defaults @@ -297,47 +298,54 @@ axios.create({ // Interceptors const requestInterceptorId: number = axios.interceptors.request.use( - async (config: AxiosRequestConfig) => { - await axios.get('/foo', { - headers: config.headers - }); - return config; - }, - (error: any) => Promise.reject(error), - {synchronous: false} + async (config) => { + await axios.get('/foo', { + headers: config.headers + }); + return config; + }, + (error: any) => Promise.reject(error), + {synchronous: false} ); axios.interceptors.request.eject(requestInterceptorId); axios.interceptors.request.use( - (config: AxiosRequestConfig) => Promise.resolve(config), - (error: any) => Promise.reject(error) + (config) => Promise.resolve(config), + (error: any) => Promise.reject(error) ); -axios.interceptors.request.use((config: AxiosRequestConfig) => config); -axios.interceptors.request.use((config: AxiosRequestConfig) => Promise.resolve(config)); +axios.interceptors.request.use((config) => config); +axios.interceptors.request.use((config) => Promise.resolve(config)); const responseInterceptorId: number = axios.interceptors.response.use( - (response: AxiosResponse) => response, - (error: any) => Promise.reject(error) + (response: AxiosResponse) => response, + (error: any) => Promise.reject(error) ); axios.interceptors.response.eject(responseInterceptorId); axios.interceptors.response.use( - (response: AxiosResponse) => Promise.resolve(response), - (error: any) => Promise.reject(error) + (response: AxiosResponse) => Promise.resolve(response), + (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 AxiosRequestConfig (or throw) - (_response) => {}, - (error: any) => Promise.reject(error) + // @ts-expect-error -- Must return an AxiosRequestConfig (or throw) + (_response) => {}, + (error: any) => Promise.reject(error) ); const voidResponseInterceptorId = axios.interceptors.response.use( - // @ts-expect-error -- Must return an AxiosResponse (or throw) - (_response) => {}, - (error: any) => Promise.reject(error) + // @ts-expect-error -- Must return an AxiosResponse (or throw) + (_response) => {}, + (error: any) => Promise.reject(error) ); axios.interceptors.request.eject(voidRequestInterceptorId); axios.interceptors.response.eject(voidResponseInterceptorId); @@ -350,7 +358,7 @@ axios.interceptors.response.clear(); // Adapters -const adapter: AxiosAdapter = (config: AxiosRequestConfig) => { +const adapter: AxiosAdapter = (config) => { const response: AxiosResponse = { data: { foo: 'bar' }, status: 200, @@ -397,28 +405,28 @@ const fn2: (arr: number[]) => string = axios.spread(fn1); // Promises axios.get('/user') - .then((response: AxiosResponse) => 'foo') - .then((value: string) => {}); + .then((response: AxiosResponse) => 'foo') + .then((value: string) => {}); axios.get('/user') - .then((response: AxiosResponse) => Promise.resolve('foo')) - .then((value: string) => {}); + .then((response: AxiosResponse) => Promise.resolve('foo')) + .then((value: string) => {}); axios.get('/user') - .then((response: AxiosResponse) => 'foo', (error: any) => 'bar') - .then((value: string) => {}); + .then((response: AxiosResponse) => 'foo', (error: any) => 'bar') + .then((value: string) => {}); axios.get('/user') - .then((response: AxiosResponse) => 'foo', (error: any) => 123) - .then((value: string | number) => {}); + .then((response: AxiosResponse) => 'foo', (error: any) => 123) + .then((value: string | number) => {}); axios.get('/user') - .catch((error: any) => 'foo') - .then((value: any) => {}); + .catch((error: any) => 'foo') + .then((value: any) => {}); axios.get('/user') - .catch((error: any) => Promise.resolve('foo')) - .then((value: any) => {}); + .catch((error: any) => Promise.resolve('foo')) + .then((value: any) => {}); // Cancellation @@ -444,17 +452,17 @@ source.cancel('Operation has been canceled.'); // AxiosError axios.get('/user') - .catch((error: AxiosError) => { - if (axios.isAxiosError(error)) { - const axiosError: AxiosError = error; - } + .catch((error: AxiosError) => { + if (axios.isAxiosError(error)) { + const axiosError: AxiosError = error; + } - // named export + // named export - if (isAxiosError(error)) { - const axiosError: AxiosError = error; - } - }); + if (isAxiosError(error)) { + const axiosError: AxiosError = error; + } + }); // FormData @@ -507,17 +515,17 @@ axios.get('/user', { // issue #5034 -function getRequestConfig1(options: AxiosRequestConfig): AxiosRequestConfig { +function getRequestConfig1(options: RawAxiosRequestConfig): RawAxiosRequestConfig { return { ...options, headers: { - ...(options.headers as RawAxiosRequestHeaders), + ...(options.headers as RawAxiosRequestHeaders), Authorization: `Bearer ...`, }, }; } -function getRequestConfig2(options: AxiosRequestConfig): AxiosRequestConfig { +function getRequestConfig2(options: RawAxiosRequestConfig): RawAxiosRequestConfig { return { ...options, headers: {