作为道具传递时 graphql 重新获取的类型是什么?

What is type of graphql refetch when passing as props?

我将 graphql refetch 作为 props 传递给组件,但我不确定类型应该是什么?

const { data, loading, refetch } = useQuery(gqlquery, {
        variables: { where: { id: id } },
    });

  <myinfo
     loading={loading}
     data={data}
     refetch={refetch}
   />

export const myinfo= ({
    refetch,
    loading,
    data,
}: myinfoProps) => {}


type myinfoProps= {
    refetch?: any;
    loading: boolean;
    data: {}
};

我想从 refetch?: any; 中删除 any 应该在那里而不是。

根据文档,refetch 的类型是:

 type myinfoProps= {
    refetch?: (options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise<UseQueryResult>;
    loading: boolean;
    data: {}
};

调用时您必须检查它是否已定义,因为它是可选的 属性 :

export const myinfo= ({
    refetch,
    loading,
    data,
}: myinfoProps) => {
  if(refetch){
         refetch(/* parameters */);
    }

}