mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
Refactored module exports; (#5162)
* Refactored build pipeline; Added module exports tests; Added missing ESM export for parity with Axios factory; Added `toFormData`, `formToJSON`, `isAxiosError`, `spread`, `isCancel`, `all` as named export to `index.d.ts`; * Added ESM entry test; * Updated README.md `installing` section; * Added TypeScript importing test; Added missed `CanceledError` & `AxiosHeaders` to `AxiosStatic` interface; * Exclude `/test/module/` from tslint;
This commit is contained in:
@@ -6,7 +6,13 @@ import axios, {
|
||||
AxiosAdapter,
|
||||
Cancel,
|
||||
CancelTokenSource,
|
||||
Canceler, AxiosProgressEvent, ParamsSerializerOptions
|
||||
Canceler, AxiosProgressEvent, ParamsSerializerOptions,
|
||||
toFormData,
|
||||
formToJSON,
|
||||
all,
|
||||
isCancel,
|
||||
isAxiosError,
|
||||
spread
|
||||
} from 'axios';
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
@@ -354,11 +360,28 @@ const promises = [
|
||||
|
||||
const promise: Promise<number[]> = axios.all(promises);
|
||||
|
||||
// axios.all named export
|
||||
|
||||
(() => {
|
||||
const promises = [
|
||||
Promise.resolve(1),
|
||||
Promise.resolve(2)
|
||||
];
|
||||
|
||||
const promise: Promise<number[]> = all(promises);
|
||||
})();
|
||||
|
||||
// axios.spread
|
||||
|
||||
const fn1 = (a: number, b: number, c: number) => `${a}-${b}-${c}`;
|
||||
const fn2: (arr: number[]) => string = axios.spread(fn1);
|
||||
|
||||
// axios.spread named export
|
||||
(() => {
|
||||
const fn1 = (a: number, b: number, c: number) => `${a}-${b}-${c}`;
|
||||
const fn2: (arr: number[]) => string = spread(fn1);
|
||||
})();
|
||||
|
||||
// Promises
|
||||
|
||||
axios.get('/user')
|
||||
@@ -396,6 +419,12 @@ axios.get('/user', {
|
||||
const cancel: Cancel = thrown;
|
||||
console.log(cancel.message);
|
||||
}
|
||||
|
||||
// named export
|
||||
if (isCancel(thrown)) {
|
||||
const cancel: Cancel = thrown;
|
||||
console.log(cancel.message);
|
||||
}
|
||||
});
|
||||
|
||||
source.cancel('Operation has been canceled.');
|
||||
@@ -407,12 +436,28 @@ axios.get('/user')
|
||||
if (axios.isAxiosError(error)) {
|
||||
const axiosError: AxiosError = error;
|
||||
}
|
||||
|
||||
// named export
|
||||
|
||||
if (isAxiosError(error)) {
|
||||
const axiosError: AxiosError = error;
|
||||
}
|
||||
});
|
||||
|
||||
// FormData
|
||||
|
||||
axios.toFormData({x: 1}, new FormData());
|
||||
|
||||
// named export
|
||||
toFormData({x: 1}, new FormData());
|
||||
|
||||
// formToJSON
|
||||
|
||||
axios.toFormData(new FormData());
|
||||
|
||||
// named export
|
||||
formToJSON(new FormData());
|
||||
|
||||
// AbortSignal
|
||||
|
||||
axios.get('/user', {signal: new AbortController().signal});
|
||||
|
||||
Reference in New Issue
Block a user