mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
fix: removed implict never
This commit is contained in:
parent
6fa0e7b602
commit
52689e24f4
@ -149,7 +149,7 @@ export interface CacheInstance {
|
||||
/**
|
||||
* The response interceptor that will be used to handle the cache.
|
||||
*/
|
||||
responseInterceptor: AxiosInterceptor<CacheAxiosResponse>;
|
||||
responseInterceptor: AxiosInterceptor<CacheAxiosResponse<any>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +168,7 @@ export interface AxiosCacheInstance extends AxiosInstance, CacheInstance {
|
||||
|
||||
interceptors: {
|
||||
request: AxiosInterceptorManager<CacheRequestConfig>;
|
||||
response: AxiosInterceptorManager<CacheAxiosResponse>;
|
||||
response: AxiosInterceptorManager<CacheAxiosResponse<never>>;
|
||||
};
|
||||
|
||||
getUri(config?: CacheRequestConfig): string;
|
||||
|
||||
@ -12,15 +12,17 @@ import type { AxiosInterceptor } from './types';
|
||||
|
||||
type CacheConfig = CacheRequestConfig & { cache?: Partial<CacheProperties> };
|
||||
|
||||
export class CacheResponseInterceptor implements AxiosInterceptor<CacheAxiosResponse> {
|
||||
export class CacheResponseInterceptor<R>
|
||||
implements AxiosInterceptor<CacheAxiosResponse<R>>
|
||||
{
|
||||
constructor(readonly axios: AxiosCacheInstance) {}
|
||||
|
||||
use = (): void => {
|
||||
this.axios.interceptors.response.use(this.onFulfilled);
|
||||
};
|
||||
|
||||
private testCachePredicate = (
|
||||
response: AxiosResponse,
|
||||
private testCachePredicate = <R>(
|
||||
response: AxiosResponse<R>,
|
||||
{ cache }: CacheConfig
|
||||
): boolean => {
|
||||
const cachePredicate =
|
||||
@ -45,7 +47,9 @@ export class CacheResponseInterceptor implements AxiosInterceptor<CacheAxiosResp
|
||||
delete this.axios.waiting[key];
|
||||
};
|
||||
|
||||
onFulfilled = async (response: CacheAxiosResponse): Promise<CacheAxiosResponse> => {
|
||||
onFulfilled = async (
|
||||
response: CacheAxiosResponse<R>
|
||||
): Promise<CacheAxiosResponse<R>> => {
|
||||
const key = this.axios.generateKey(response.config);
|
||||
response.id = key;
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import type { CachePredicateObject } from './types';
|
||||
|
||||
export function checkPredicateObject(
|
||||
response: AxiosResponse,
|
||||
export function checkPredicateObject<R>(
|
||||
response: AxiosResponse<R>,
|
||||
{ statusCheck, containsHeaders: containsHeader, responseMatch }: CachePredicateObject
|
||||
): boolean {
|
||||
if (statusCheck) {
|
||||
|
||||
@ -3,7 +3,7 @@ import type { CacheRequestConfig } from '../axios/types';
|
||||
|
||||
export type CachePredicate =
|
||||
| CachePredicateObject
|
||||
| ((response: AxiosResponse) => boolean);
|
||||
| (<R>(response: AxiosResponse<R>) => boolean);
|
||||
|
||||
export type CachePredicateObject = {
|
||||
/**
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import { checkPredicateObject } from '../../src/util/cache-predicate';
|
||||
|
||||
const Response = (config: Partial<AxiosResponse>): AxiosResponse => {
|
||||
const Response = <R>(config: Partial<AxiosResponse<R>>): AxiosResponse<R> => {
|
||||
return {
|
||||
status: 200,
|
||||
headers: {},
|
||||
config: {},
|
||||
data: {},
|
||||
data: {} as R,
|
||||
statusText: '',
|
||||
request: {},
|
||||
...config
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user