Skip to content

Cannot use defer on a loader with typesafeBrowserRouter #16

Description

@stevan-borus

I have a loader with defer:

import { defer } from 'react-router-typesafe';
...

export const dashboardLoader = (queryClient: QueryClient) => () => {
  return defer<{
    dashboardInfo: Promise<DashboardType>;
  }>({
    dashboardInfo: queryClient.ensureQueryData(dashboardInfoQueries.info()),
  });
};

and I have a RouteObject like this in typesafeBrowserRouter:

{
   index: true,
   loader: dashboardLoader(queryClient),
   async lazy() {
         const { Dashboard } = await import('@/views/dashboard/Dashboard');

         return { element: <Dashboard /> };
   },
},

I get an error: Type () => DeferredData<{ dashboardInfo: Promise<DashboardType>; }> is not assignable to type NarrowKeys<boolean | LoaderFunction<any> | undefined>

This doesn't happen when I am using a regular loader without defer.

Oh, and when I just switch from typesafeBrowserRouter to createBrowserRouter everything works just fine since then, loader doesn't have that NarrowKeys type.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions