fix: removed implict never

This commit is contained in:
Hazork 2021-10-09 14:36:36 -03:00
parent 6fa0e7b602
commit 52689e24f4
5 changed files with 15 additions and 11 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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 = {
/**

View File

@ -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