TanStackT
TanStack3mo ago
14 replies
dangerous-fuchsia

Wrong type inference from beforeLoad/loader when using complex objects in return

I've added all the necessary types and declarations, started the fresh new project. I want to prefetch the product from an api and i have all the necessary types infered.

Here's an example of the code:

export const Route = createFileRoute(
  '/$locale/_layout/(main)/_main/product/$handle'
)({
  beforeLoad: async ({ params: { handle }, context: { region } }) => {
    const product = await queryClient.fetchQuery(
      getProductByHandleQueryOptions({ handle, region_id: region.id })
    );

    if (!product) {
      throw notFound({
        routeId: Route.id,
        data: { handle },
      });
    }

    return { product };
  },
  component: ProductTemplate,
});
Was this page helpful?