Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ESM default import This expression is not callable #230

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,65 @@
import * as axios from 'axios'
import * as axios from 'axios';

interface IAxiosRetry {
(
axios: axios.AxiosStatic | axios.AxiosInstance,
axiosRetryConfig?: IAxiosRetry.IAxiosRetryConfig
): void;
export = IAxiosRetry;
export as namespace axiosRetry;
declare const IAxiosRetry: IAxiosRetry.AxiosRetry;

isNetworkError(error: Error): boolean;
isRetryableError(error: Error): boolean;
isSafeRequestError(error: Error): boolean;
isIdempotentRequestError(error: Error): boolean;
isNetworkOrIdempotentRequestError(error: Error): boolean;
exponentialDelay(retryNumber?: number, error?: Error, delayFactor?: number): number;
}
declare namespace IAxiosRetry {
interface AxiosRetry {
(axios: axios.AxiosStatic | axios.AxiosInstance, axiosRetryConfig?: AxiosRetryConfig): AxiosRetryReturn;

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;
isNetworkError(error: Error): boolean;
isRetryableError(error: Error): boolean;
isSafeRequestError(error: Error): boolean;
isIdempotentRequestError(error: Error): boolean;
isNetworkOrIdempotentRequestError(error: Error): boolean;
exponentialDelay(retryNumber?: number, error?: Error, delayFactor?: number): number;
}

declare namespace IAxiosRetry {
export interface IAxiosRetryConfig {
interface AxiosRetryConfig {
/**
* The number of times to retry before failing
* default: 3
*
* @type {number}
*/
retries?: number,
retries?: number;
/**
* Defines if the timeout should be reset between retries
* default: false
*
* @type {boolean}
*/
shouldResetTimeout?: boolean,
shouldResetTimeout?: boolean;
/**
* A callback to further control if a request should be retried.
* default: it retries if it is a network error or a 5xx error on an idempotent request (GET, HEAD, OPTIONS, PUT or DELETE).
*
* @type {Function}
*/
retryCondition?: (error: axios.AxiosError) => boolean | Promise<boolean>,
retryCondition?: (error: axios.AxiosError) => boolean | Promise<boolean>;
/**
* A callback to further control the delay between retry requests. By default there is no delay.
*
* @type {Function}
*/
retryDelay?: (retryCount: number, error: axios.AxiosError) => number
retryDelay?: (retryCount: number, error: axios.AxiosError) => number;
/**
* A callback to get notified when a retry occurs, the number of times it has occurre, and the error
*
* @type {Function}
*/
onRetry?: (retryCount: number, error: axios.AxiosError, requestConfig: axios.AxiosRequestConfig) => void
onRetry?: (
retryCount: number,
error: axios.AxiosError,
requestConfig: axios.AxiosRequestConfig
) => void;
}
}

declare const axiosRetry: IAxiosRetry;

export type IAxiosRetryConfig = IAxiosRetry.IAxiosRetryConfig;

export default axiosRetry;
interface AxiosRetryReturn {
/**
* The interceptorId for the request interceptor
*/
requestInterceptorId: number;
/**
* The interceptorId for the response interceptor
*/
responseInterceptorId: number;
}
}

declare module 'axios' {
export interface AxiosRequestConfig {
'axios-retry'?: IAxiosRetryConfig;
interface AxiosRequestConfig {
'axios-retry'?: IAxiosRetry.AxiosRetryConfig;
}
}
29 changes: 29 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// tslint:disable-next-line: no-relative-import-in-test
import axiosRetry, { isNetworkError, exponentialDelay } from '.';
import axios from 'axios';

const instance = axios.create();

axiosRetry(); // $ExpectError

axiosRetry(axios); // $ExpectType AxiosRetryReturn
axiosRetry(instance); // $ExpectType AxiosRetryReturn

axiosRetry(axios, { retries: 3, shouldResetTimeout: false }); // $ExpectType AxiosRetryReturn

axiosRetry(axios, { retryCondition: (e) => e.name === 'error' }); // $ExpectType AxiosRetryReturn
axiosRetry(axios, { retryCondition: isNetworkError }); // $ExpectType AxiosRetryReturn
axiosRetry(axios, { retryCondition: axiosRetry.isNetworkError }); // $ExpectType AxiosRetryReturn
axiosRetry(axios, { retryCondition: exponentialDelay }); // $ExpectError

axiosRetry(axios, { retryDelay: (count, error) => 1 }); // $ExpectType AxiosRetryReturn
axiosRetry(axios, { retryDelay: exponentialDelay }); // $ExpectType AxiosRetryReturn
axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay }); // $ExpectType AxiosRetryReturn
axiosRetry(axios, { retryDelay: isNetworkError }); // $ExpectError

// $ExpectType AxiosRetryReturn
axiosRetry(axios, {
onRetry: (count, error, config) => {
console.log(error);
}
});
Loading