I have a simple hook that wraps the axios call in React Query:
function useInviteTeamMember(
onSuccess?: Handler,
onError?: Handler,
): UseMutationResult<User> {
const mutation = useMutation(
(payload: InviteMutationVars) => {
return postInviteTeamMember(payload);
},
{
onSuccess: (data) => {
...
The issue I have is that from the above definition you would expect the result to be of type User. Even in that onSuccess handler (data) is according to intellisense of type User. But it's not. To get the actual User object I have to do data['data'].
The actual post function is the root cause I think, since it types the Promise with :
export function postInviteTeamMember(payload: InviteMutationVars): Promise<User> {
return client.post('/user/invite/team', payload);
}
So how can I rewrite this code so that the type of 'data' is correct?