Help with loader context type safety. #2668
-
Hi there, I'm trying to follow the Kitchen Sink with React Query File Based example and I'm unsure if I'm doing something wrong. I start by setting up the query client and the router, including the const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
retry: false,
},
},
});
const router = createRouter({
routeTree,
defaultPreload: "intent",
context: { queryClient },
defaultPreloadStaleTime: 0,
});
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
} When trying to access the context in the loader I get the following typescript error In order to fix this error I need to explicitly define the type of the context in the loader fn like this loader: (opts) =>
(opts.context as { queryClient: QueryClient }).queryClient.ensureQueryData(
categoryQueryOptions
), Is this expected? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@dosmond did you perhaps forget this bit, https://github.com/TanStack/router/blob/main/examples/react/kitchen-sink-react-query-file-based/src/routes/__root.tsx#L5, using createRootRouterWithContext? |
Beta Was this translation helpful? Give feedback.
@dosmond did you perhaps forget this bit, https://github.com/TanStack/router/blob/main/examples/react/kitchen-sink-react-query-file-based/src/routes/__root.tsx#L5, using createRootRouterWithContext?