From f2d4a146c513ef8eaac4dff3a1a7ecf0c3d8f72f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 11:34:49 -0400 Subject: [PATCH] refactor: add CancelablePromise sub-type so we can call promise.cancel --- src/axios.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/axios.ts b/src/axios.ts index 5eed910..b9cf63c 100644 --- a/src/axios.ts +++ b/src/axios.ts @@ -1,10 +1,14 @@ import Axios, {AxiosError, AxiosRequestConfig} from "axios"; import {S5Error} from "#client.js"; +export interface CancelablePromise extends Promise { + cancel: () => void; +} + export const customInstance = ( config: AxiosRequestConfig, options?: AxiosRequestConfig, -): Promise => { +): CancelablePromise => { const source = Axios.CancelToken.source(); /* @@ -33,5 +37,5 @@ export const customInstance = ( source.cancel("Query was cancelled"); }; - return promise; + return promise as CancelablePromise; };