TanStackT
TanStack2y ago
1 reply
worthy-rose

TypeScript errors for createQuery(options, queryClient)

If I do the following:

        const tsqSessionQueryOptions = () => {
          return queryOptions({
            queryKey: ['userSession'],
            queryFn: async () => {
              return { session: 'fake-thing' };
            },
            staleTime: 1000 * 60 * 10, // 10 minutes and we don't trust it anmore
            refetchInterval: 1000 * 60 * 5, // 5 minutes and we recheck if we can
            retry: true,
            placeholderData: keepPreviousData,
            deferStream: true,
          });
        };

        const session = createQuery(tsqSessionQueryOptions);


I have no error in TS. But if I change the last line to:

createQuery(tsqSessionQueryOptions, myQueryClient);


the typescript errors out expecting initialData to be set and ignores the non intiailized version of the type. I need to pas sin the query client since this happens outside the routing tree and contexts.

5.4.5 typescript.
Was this page helpful?