tRPCttRPC
Powered by
MugetsuM
tRPC•17mo ago•
1 reply
Mugetsu

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>
error: TRPCClientError<AppRouter>
this does satisfy the function and internal of it but doesn't comply with the onError handlers
onError: onApiError
onError: onApiError
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to extract mutation type
MugetsuMMugetsu / ❓-help
2y ago
onError callback type
MugetsuMMugetsu / ❓-help
2y ago
Mutation type issue
OutisOOutis / ❓-help
4y ago