diff --git a/src/adaptive.ts b/src/adaptive.ts index 91b5c2a..0151557 100644 --- a/src/adaptive.ts +++ b/src/adaptive.ts @@ -28,7 +28,7 @@ export default function adaptive(): Adapter | undefined { let adapter: Adapter | undefined; - while (stack.length !== 0 && adapter === undefined) { + while (stack.length !== 0 && adapter === void 0) { try { adapter = (stack.shift() as () => Adapter)(); } catch (err) {} diff --git a/src/core/Axios.ts b/src/core/Axios.ts index b897546..17cc9ae 100644 --- a/src/core/Axios.ts +++ b/src/core/Axios.ts @@ -43,7 +43,7 @@ export default class AxiosClass implements Axios { } public options(url: string, config?: AxiosRequestConfig): Promise> { - return this._requestMethodWithoutParams('options', url, undefined, config); + return this._requestMethodWithoutParams('options', url, void 0, config); } public get(url: string, params?: Params, config?: AxiosRequestConfig): Promise> { @@ -67,11 +67,11 @@ export default class AxiosClass implements Axios { } public trace(url: string, config?: AxiosRequestConfig): Promise> { - return this._requestMethodWithoutParams('trace', url, undefined, config); + return this._requestMethodWithoutParams('trace', url, void 0, config); } public connect(url: string, config?: AxiosRequestConfig): Promise> { - return this._requestMethodWithoutParams('connect', url, undefined, config); + return this._requestMethodWithoutParams('connect', url, void 0, config); } /** diff --git a/src/core/dispatchRequest.ts b/src/core/dispatchRequest.ts index 561b7d8..54c2357 100644 --- a/src/core/dispatchRequest.ts +++ b/src/core/dispatchRequest.ts @@ -39,7 +39,7 @@ export default function dispatchRequest(config: AxiosRequestConfig): Promise { - if (config2[key] !== undefined) { + if (config2[key] !== void 0) { config[key] = config2[key] as any; } }); @@ -51,9 +51,9 @@ function priorityFromConfig2( config2: AxiosRequestConfig ) { keys.forEach((key) => { - if (config2[key] !== undefined) { + if (config2[key] !== void 0) { config[key] = config2[key] as any; - } else if (config1[key] !== undefined) { + } else if (config1[key] !== void 0) { config[key] = config1[key] as any; } }); diff --git a/src/core/request.ts b/src/core/request.ts index 5878eee..f395fc9 100644 --- a/src/core/request.ts +++ b/src/core/request.ts @@ -27,7 +27,7 @@ export default function request(config: AxiosRequestConfig): Promise { }); it('适配失败', () => { - global.wx = undefined; + global.wx = void 0; expect(adaptive()).toBeUndefined(); }); diff --git a/test/axios.test.ts b/test/axios.test.ts index 2c30b1c..7b55b29 100644 --- a/test/axios.test.ts +++ b/test/axios.test.ts @@ -2,7 +2,7 @@ import axios from '../src/axios'; describe('测试 src/axios.ts', () => { it('default', () => { - axios('/test').then(undefined, (error) => { + axios('/test').then(void 0, (error) => { expect(error.isAxiosError).toBe(true); expect(error.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台'); }); diff --git a/test/core/Axios.test.ts b/test/core/Axios.test.ts index bc8d368..f946462 100644 --- a/test/core/Axios.test.ts +++ b/test/core/Axios.test.ts @@ -49,7 +49,7 @@ describe('测试 src/core/Axios.ts', () => { method: 'post', data: '', }) - .then(undefined, (error) => expect(error.data).toBe('interceptors_response')); + .then(void 0, (error) => expect(error.data).toBe('interceptors_response')); instance.interceptors.request.use((config) => Promise.reject(config)); @@ -58,6 +58,6 @@ describe('测试 src/core/Axios.ts', () => { method: 'post', data: '', }) - .then(undefined, (error) => expect(error.method).toBe('post')); + .then(void 0, (error) => expect(error.method).toBe('post')); }); }); diff --git a/test/core/InterceptorManager.test.ts b/test/core/InterceptorManager.test.ts index e674237..1ef48dc 100644 --- a/test/core/InterceptorManager.test.ts +++ b/test/core/InterceptorManager.test.ts @@ -15,8 +15,8 @@ describe('测试 src/core/InterceptorManager.ts', () => { const interceptor = new InterceptorManager(); const executor1 = jest.fn(); const executor2 = jest.fn(); - const id1 = interceptor.use(() => undefined); - const id2 = interceptor.use(() => undefined); + const id1 = interceptor.use(() => void 0); + const id2 = interceptor.use(() => void 0); interceptor.forEach(executor1); // executor1 应该被执行了两次 @@ -49,7 +49,7 @@ describe('测试 src/core/InterceptorManager.ts', () => { const interceptor = new InterceptorManager(); interceptor.use( - () => undefined, + () => void 0, (error: any) => { expect(error).toBe('error'); return Promise.reject(error); diff --git a/test/core/dispatchRequest.test.ts b/test/core/dispatchRequest.test.ts index a72efa5..7cfe16f 100644 --- a/test/core/dispatchRequest.test.ts +++ b/test/core/dispatchRequest.test.ts @@ -5,7 +5,7 @@ import isCancel from '../../src/cancel/isCancel'; describe('测试 src/core/dispatchRequest.ts', () => { it('默认', () => { - dispatchRequest({}).then(undefined, (err) => { + dispatchRequest({}).then(void 0, (err) => { expect(err.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台'); }); }); @@ -20,7 +20,7 @@ describe('测试 src/core/dispatchRequest.ts', () => { validateStatus(status) { return status === -1; }, - }).then(undefined, (err) => expect(err.response.status).toBe(200)); + }).then(void 0, (err) => expect(err.response.status).toBe(200)); }); it('自定义错误处理', () => { @@ -34,7 +34,7 @@ describe('测试 src/core/dispatchRequest.ts', () => { error.errorHandler = true; return error; }, - }).then(undefined, (error) => expect(error.errorHandler).toBe(true)); + }).then(void 0, (error) => expect(error.errorHandler).toBe(true)); }); it('取消请求', () => { @@ -50,6 +50,6 @@ describe('测试 src/core/dispatchRequest.ts', () => { cancelToken: new CancelToken(function executor(c) { cancel = c; }), - }).then(undefined, (err) => expect(isCancel(err)).toBe(true)); + }).then(void 0, (err) => expect(isCancel(err)).toBe(true)); }); }); diff --git a/test/core/mergeConfig.test.ts b/test/core/mergeConfig.test.ts index 0ce1b3c..67071f3 100644 --- a/test/core/mergeConfig.test.ts +++ b/test/core/mergeConfig.test.ts @@ -8,7 +8,7 @@ describe('测试 src/core/mergeConfig.ts', () => { expect(mergeConfig({ baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' }); - expect(mergeConfig(undefined, { baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' }); + expect(mergeConfig(void 0, { baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' }); }); it('只取 config2', () => { diff --git a/test/core/request.test.ts b/test/core/request.test.ts index 8dff227..87ad884 100644 --- a/test/core/request.test.ts +++ b/test/core/request.test.ts @@ -4,7 +4,7 @@ import isCancel from '../../src/cancel/isCancel'; describe('测试 src/core/request.ts', () => { it('默认', () => { - request({}).then(undefined, (err) => + request({}).then(void 0, (err) => expect(err.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台') ); }); @@ -16,7 +16,7 @@ describe('测试 src/core/request.ts', () => { return 'task'; }, - }).then(undefined, (err) => expect(err.message).toBe('配置不正确或者网络异常')); + }).then(void 0, (err) => expect(err.message).toBe('配置不正确或者网络异常')); }); it('取消请求', () => { @@ -31,6 +31,6 @@ describe('测试 src/core/request.ts', () => { cancelToken: new CancelToken(function executor(c) { c(); }), - }).then(undefined, (err) => expect(isCancel(err)).toBe(true)); + }).then(void 0, (err) => expect(isCancel(err)).toBe(true)); }); }); diff --git a/test/core/transformRequest.test.ts b/test/core/transformRequest.test.ts index 2afa678..c7523f8 100644 --- a/test/core/transformRequest.test.ts +++ b/test/core/transformRequest.test.ts @@ -5,16 +5,16 @@ describe('测试 src/core/transformRequest.ts', () => { expect(transformRequest({})).toEqual({ url: '/', method: 'GET', - headers: undefined, - data: undefined, - dataType: undefined, - enableCache: undefined, - enableHttp2: undefined, - enableQuic: undefined, - header: undefined, - responseType: undefined, - sslVerify: undefined, - timeout: undefined, + headers: void 0, + data: void 0, + dataType: void 0, + enableCache: void 0, + enableHttp2: void 0, + enableQuic: void 0, + header: void 0, + responseType: void 0, + sslVerify: void 0, + timeout: void 0, }); }); diff --git a/test/core/transformResponse.test.ts b/test/core/transformResponse.test.ts index e0c784f..13ed1b6 100644 --- a/test/core/transformResponse.test.ts +++ b/test/core/transformResponse.test.ts @@ -8,8 +8,8 @@ describe('测试 src/core/transformResponse.ts', () => { data: {}, headers: {}, config: {}, - cookies: undefined, - profile: undefined, + cookies: void 0, + profile: void 0, }); }); @@ -20,8 +20,8 @@ describe('测试 src/core/transformResponse.ts', () => { data: {}, headers: { status: 'ok' }, config: {}, - cookies: undefined, - profile: undefined, + cookies: void 0, + profile: void 0, }); }); it('statusCode + header', () => { @@ -31,8 +31,8 @@ describe('测试 src/core/transformResponse.ts', () => { data: {}, headers: { status: 'ok' }, config: {}, - cookies: undefined, - profile: undefined, + cookies: void 0, + profile: void 0, }); }); }); diff --git a/test/helpers/buildURL.test.ts b/test/helpers/buildURL.test.ts index 4c3a709..8cbb271 100644 --- a/test/helpers/buildURL.test.ts +++ b/test/helpers/buildURL.test.ts @@ -74,7 +74,7 @@ describe('测试 src/helpers/buildURL.ts', () => { expect( buildURL('/test', { null: null, - undefined: undefined, + undefined: void 0, NaN: NaN, }) ).toBe('/test');