MugetsuM
tRPC2y ago
5 replies
Mugetsu

onError callback type

I want to have a callback onError passed from parent component to the child which has mutation call. onError should be passed directly to the mutation options but also accept plan Error type and undefined. But I struggle how to type it correctly.


export const DownloadTrigger = ({
  onError,
} {
  onError: ReactQueryOptions['batch']['triggerDownload']['onError'];  // This doesn't quire work is there more generic type or I should just add Error | undefined?
}) => {
  const downloadMutation = api.batch.triggerDownload.useMutation({
    onError,
  });

  useEffect(() => {
    handleFile()
      .catch((err: Error) => {
        // @ts-ignore
        onError(err);
      })
      .finally(() => {
        // @ts-ignore
        onError(undefined);
      });
Was this page helpful?