import axios , { AxiosInstance , AxiosRequestConfig , AxiosResponse , CancelStatic , CancelTokenStatic } from 'axios' ; import { RestypedBase , RestypedIndexedBase , RestypedRoute } from 'restyped' ; export interface TypedAxiosRequestConfig < API extends RestypedIndexedBase , Path extends Extract < keyof API , string > , Method extends keyof API [ Path ] , RouteDef extends RestypedRoute = API [ Path ] [ Method ] > extends AxiosRequestConfig { url ? : Path ; method ? : Extract < Method , string > ; params ? : RouteDef [ 'query' ] ; data ? : RouteDef [ 'body' ] ; } export interface TypedAxiosResponse < API extends RestypedIndexedBase , Path extends Extract < keyof API , string > , Method extends keyof API [ Path ] , RouteDef extends RestypedRoute = API [ Path ] [ Method ] > extends AxiosResponse { data : RouteDef [ 'response' ] ; config : TypedAxiosRequestConfig < API , Path , Method > ; } export interface TypedAxiosInstance < API extends RestypedBase = any > extends AxiosInstance { request < Path extends Extract < keyof API , string > , Method extends keyof API [ Path ] = 'GET' > ( config ) : Promise < TypedAxiosResponse < API , Path , Method > > ; get < Path extends Extract < keyof API , string > > ( url , config ? ) : Promise < TypedAxiosResponse < API , Path , 'GET' > > ; delete < Path extends Extract < keyof API , string > > ( url , config ? ) : Promise < TypedAxiosResponse < API , Path , 'DELETE' > > ; head < Path extends Extract < keyof API , string > > ( url , config ? ) : Promise < TypedAxiosResponse < API , Path , 'HEAD' > > ; post < Path extends Extract < keyof API , string > > ( url , data ? , config ? ) : Promise < TypedAxiosResponse < API , Path , 'POST' > > ; put < Path extends Extract < keyof API , string > > ( url , data ? , config ? ) : Promise < TypedAxiosResponse < API , Path , 'PUT' > > ; patch < Path extends Extract < keyof API , string > > ( url , data ? , config ? ) : Promise < TypedAxiosResponse < API , Path , 'PATCH' > > ; } export interface TypedAxiosStatic < API extends RestypedBase = any > extends TypedAxiosInstance < API > { < Path extends Extract < keyof API , string > , Method extends keyof API [ Path ] = 'GET' > ( config ) : Promise < TypedAxiosResponse < API , Path , Method > > ; < Path extends Extract < keyof API , string > , Method extends keyof API [ Path ] > ( url , config ? ) : Promise < TypedAxiosResponse < API , Path , Method > > ; create < T extends API > ( config ? ) : TypedAxiosInstance < T > ; Cancel : CancelStatic ; CancelToken : CancelTokenStatic ; isCancel ( value ) : boolean ; all < T > ( values ) : Promise < T [ ] > ; spread < T , R > ( callback ) : ( array : T [ ] ) => R ; } const TypedAxios = axios as any ; export default TypedAxios ;