Theo's Typesafe CultTTC
Theo's Typesafe Cult16mo ago
4 replies
Mugetsu

tRPC mutation onError handler error type for shared logic

I have two mutations on my frontend that should handle the response in the same way. So I extract the onError function so these two mutations can re-use the logic but I have a problem on how to type the error so the in function handling is pleased with typescript and the onError handler is also pleased.
//  What type of the error should be here?
const onApiError = (error: ???) => {...}


const createMutation = api.location.create.useMutation({    onError: onApiError  });
const editMutation = api.location.edit.useMutation({    onError: onApiError  });


I have tried like
error: TRPCClientError<AppRouter> this does satisfy the function and internal of it but doesn't comply with the onError handlers onError: onApiError
Was this page helpful?