Mugetsu
Mugetsu3mo ago

How to get mutation onError typescript type

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 });
// 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
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?