Skip to content

Commit

Permalink
fix: enable name import
Browse files Browse the repository at this point in the history
  • Loading branch information
yutak23 committed Nov 15, 2023
1 parent 40d1ed9 commit 97965ea
Show file tree
Hide file tree
Showing 4 changed files with 2,117 additions and 194 deletions.
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ export default IAxiosRetry;
export as namespace axiosRetry;
declare const IAxiosRetry: IAxiosRetry.AxiosRetry;

export type IAxiosRetryConfig = IAxiosRetry.IAxiosRetryConfig;
export type IAxiosRetryConfigExtended = IAxiosRetry.IAxiosRetryConfigExtended;
export type IAxiosRetryReturn = IAxiosRetry.IAxiosRetryReturn;

export function isNetworkError(error: Error): boolean;
export function isRetryableError(error: Error): boolean;
export function isSafeRequestError(error: Error): boolean;
export function isIdempotentRequestError(error: Error): boolean;
export function isNetworkOrIdempotentRequestError(error: Error): boolean;
export function exponentialDelay(retryNumber?: number, error?: Error, delayFactor?: number): number;

declare namespace IAxiosRetry {
export interface AxiosRetry {
(
Expand Down
58 changes: 58 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expectType } from 'tsd';
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
import axiosRetry, {
IAxiosRetryConfig,
IAxiosRetryConfigExtended,
IAxiosRetryReturn,
exponentialDelay,
isIdempotentRequestError,
isNetworkError,
isNetworkOrIdempotentRequestError,
isRetryableError,
isSafeRequestError
} from './index.js';

const axiosInstance = axios.create();

expectType<IAxiosRetryReturn>(axiosRetry(axios));
expectType<IAxiosRetryReturn>(axiosRetry(axiosInstance));

const axiosRetryConfig: IAxiosRetryConfig = {
retries: 3,
shouldResetTimeout: true,
retryCondition: (error: AxiosError) => {
return true;
},
retryDelay: (retryCount: number, error: AxiosError) => {
return 100;
},
onRetry: (retryCount: number, error: AxiosError, requestConfig: AxiosRequestConfig) => {
const axiosRetryConfig: IAxiosRetryConfigExtended | undefined = requestConfig['axios-retry'];
console.log(retryCount, error, requestConfig, axiosRetryConfig);

expectType<IAxiosRetryConfigExtended | undefined>(requestConfig['axios-retry']);
expectType<number | undefined>(axiosRetryConfig?.retryCount);
expectType<number | undefined>(axiosRetryConfig?.lastRequestTime);
}
};
expectType<IAxiosRetryReturn>(axiosRetry(axios, axiosRetryConfig));

expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: axiosRetry.isNetworkError }));
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: axiosRetry.isRetryableError }));
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: axiosRetry.isSafeRequestError }));
expectType<IAxiosRetryReturn>(
axiosRetry(axios, { retryCondition: axiosRetry.isIdempotentRequestError })
);
expectType<IAxiosRetryReturn>(
axiosRetry(axios, { retryCondition: axiosRetry.isNetworkOrIdempotentRequestError })
);
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay }));

expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: isNetworkError }));
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: isRetryableError }));
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: isSafeRequestError }));
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryCondition: isIdempotentRequestError }));
expectType<IAxiosRetryReturn>(
axiosRetry(axios, { retryCondition: isNetworkOrIdempotentRequestError })
);
expectType<IAxiosRetryReturn>(axiosRetry(axios, { retryDelay: exponentialDelay }));
Loading

0 comments on commit 97965ea

Please sign in to comment.