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: enable name import #252

Closed
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
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;
Comment on lines +11 to +16
Copy link

@rchl rchl Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were not exported directly before. Those were exported through AxiosRetry which should be exported instead.

I'd still want you to answer #250 (comment) more specifically because I'm not sure why the export = syntax doesn't work for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were not exported directly before. Those were exported through AxiosRetry which should be exported instead.

This is to conform to the specification in JavaScript. It is also possible to name import the isNetworkError function as follows.
This time, it has been modified accordingly.

image

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you can export those since it's a "new feature" but you also have to export AxiosRetry since it was exported before and it was possible to do import { AxiosRetry } from 'axios-retry' while it's not possible with those changes.


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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that name import is working here (and that axiosRetry is able to import default).


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
Loading