You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to extract some of my catcher functions to reuse them in multiple places but can't make TypeScript satisfied.
importwretch,{Wretch,WretchError,WretchErrorCallback}from'wretch';// Here I want `error` and `req` be properly typedconstrenewCredentials: ClientErrorCallback=async(error,req)=>{// Renew credentialsconsttoken=awaitwretch('/renewtoken').get().text();// storeToken(token);// Replay the original request with new credentialsreturnreq.auth(token).get().unauthorized((err: WretchError)=>{throwerr;}).json();};constclient=wretch('/api/v1').resolve((chain)=>chain.unauthorized(renewCredentials).forbidden(renewCredentials));typeInferClientErrorCallback<Client>=ClientextendsWretch<infer T, infer C, infer R>
? WretchErrorCallback<T,C,R>
: never;typeClientErrorCallback=InferClientErrorCallback<typeofclient>
I tried to create an infer type to get the right WretchErrorCallback to be used in all of the catcher functions, but without luck. I always end up with this error:
I think you'll get the idea from the example code above. I'd very appreciate any help 🙏
importwretch,{Wretch,WretchError,WretchErrorCallback}from'./dist';asyncfunctionrenewCredentials<T,C,Rextendsundefined>(error: WretchError,req: T&Wretch<T,C,R>){// Renew credentialsconsttoken=awaitwretch('/renewtoken').get().text();// storeToken(token);// Replay the original request with new credentialsreturnreq.auth(token).get().unauthorized(err=>{throwerr;}).json();};constclient=wretch('/api/v1').resolve((chain)=>chain.unauthorized(renewCredentials).forbidden(renewCredentials));
I've been trying to extract some of my catcher functions to reuse them in multiple places but can't make TypeScript satisfied.
I tried to create an infer type to get the right
WretchErrorCallback
to be used in all of the catcher functions, but without luck. I always end up with this error:I think you'll get the idea from the example code above. I'd very appreciate any help 🙏
The code above in a live environment: https://stackblitz.com/edit/vitejs-vite-effanv?file=src%2Fmain.ts
The text was updated successfully, but these errors were encountered: