Skip to content

Commit

Permalink
fix: keeping backward compatibility, propagate AxiosResponse where it…
Browse files Browse the repository at this point in the history
… should be
  • Loading branch information
ArnaudBuchholz committed Dec 19, 2024
1 parent 45715f1 commit 7b10ca9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cache/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface CacheAxiosResponse<R = any, D = any> extends AxiosResponse<R, D
*
* @see https://axios-cache-interceptor.js.org/config/response-object#id
*/
id?: string;
id: string;

/**
* A simple boolean indicating if the request returned data from the cache or from the
Expand All @@ -43,7 +43,7 @@ export interface CacheAxiosResponse<R = any, D = any> extends AxiosResponse<R, D
*
* @see https://axios-cache-interceptor.js.org/config/response-object#cached
*/
cached?: boolean;
cached: boolean;

/**
* A simple boolean indicating if the request returned data is from valid or stale cache.
Expand Down Expand Up @@ -124,7 +124,7 @@ export interface AxiosCacheInstance extends CacheInstance, AxiosInstance {

interceptors: {
request: AxiosInterceptorManager<InternalCacheRequestConfig>;
response: AxiosInterceptorManager<CacheAxiosResponse>;
response: AxiosInterceptorManager<AxiosResponse>;
};

/** @template D The type that the request body use */
Expand Down
4 changes: 2 additions & 2 deletions src/cache/cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Method } from 'axios';
import type { AxiosResponse, Method } from 'axios';
import type { Deferred } from 'fast-defer';
import type { HeaderInterpreter } from '../header/types.js';
import type { AxiosInterceptor } from '../interceptors/build.js';
Expand Down Expand Up @@ -321,7 +321,7 @@ export interface CacheInstance {
* @default defaultResponseInterceptor
* @see https://axios-cache-interceptor.js.org/config#responseinterceptor
*/
responseInterceptor: AxiosInterceptor<CacheAxiosResponse<unknown, unknown>>;
responseInterceptor: AxiosInterceptor<AxiosResponse<unknown, unknown>>;

/**
* The debug option will print debug information in the console. It is good if you need
Expand Down
5 changes: 3 additions & 2 deletions src/interceptors/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { CacheAxiosResponse, InternalCacheRequestConfig } from '../cache/axios.js';
import type { AxiosResponse } from 'axios';
import type { InternalCacheRequestConfig } from '../cache/axios.js';

/** See {@link AxiosInterceptorManager} */
export interface AxiosInterceptor<T> {
Expand All @@ -11,4 +12,4 @@ export interface AxiosInterceptor<T> {
}

export type RequestInterceptor = AxiosInterceptor<InternalCacheRequestConfig<unknown, unknown>>;
export type ResponseInterceptor = AxiosInterceptor<CacheAxiosResponse<unknown, unknown>>;
export type ResponseInterceptor = AxiosInterceptor<AxiosResponse<unknown, unknown>>;
2 changes: 1 addition & 1 deletion src/interceptors/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
}
};

const onFulfilled: ResponseInterceptor['onFulfilled'] = async (response) => {
const onFulfilled: ResponseInterceptor['onFulfilled'] = async (response: CacheAxiosResponse) => {
// When response.config is not present, the response is indeed a error.
if (!response?.config) {
if (__ACI_DEV__) {
Expand Down

0 comments on commit 7b10ca9

Please sign in to comment.