1

告诉打字稿的正确方法是什么,即函数Variables参数的接口myMutation

    interface Variables {
      uuid: string;
      value: string;
    }

    const { mutate: myMutation } = useMutation(myGqlMutation);

我想避免像这样使用 myMutation :

 myMutation({
     uuid: '....',
     value: '....',
 } as any); // get rid of any here ... 
4

1 回答 1

2

useMutation使用generic进行注释,如下所示:

interface Variables {
  uuid: string;
  value: string;
}

const { mutate: myMutation } = useMutation<{ mutation: Variables }>(myGqlMutation);

另外,查看文档

于 2020-09-25T20:09:03.990 回答