Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding head to createFileRoute breaks type inference of loader #3491

Open
graup opened this issue Feb 20, 2025 · 0 comments
Open

Adding head to createFileRoute breaks type inference of loader #3491

graup opened this issue Feb 20, 2025 · 0 comments
Labels
types Changes to the typescript types

Comments

@graup
Copy link

graup commented Feb 20, 2025

Which project does this relate to?

Start

Describe the bug

Normally, Route.useLoaderData is typed according to the return type of loader:

function getConnectionFn({ data }: { data: {platformId: string}}) {
  return Promise.resolve({platformId: 'foobar'});
}

export const Route = createFileRoute("/platform/$platformId")({
  component: RouteComponent,
  loader: async ({ params }) => {
    const existingData = await getConnectionFn({
      data: { platformId: params.platformId },
    });
    return { existingData };
  },
});

function RouteComponent() {
  const params = Route.useParams();
  const { existingData } = Route.useLoaderData();
  //      ^?: const existingData: { platformId: string }

  return `${params.platformId}, ${existingData.platformId}`;
}

However, adding head breaks this inference:

+ head: ({ params }) => ({
+    meta: [
+      {
+        title: `Configure ${params.platformId}`,
+     },
+   ],
+  }),
  const { existingData } = Route.useLoaderData();
  //      ^?: const existingData: any

Steps to Reproduce the Bug or Issue

TS Playground

Platform

  • Version: 1.107.0
@schiller-manuel schiller-manuel added the types Changes to the typescript types label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Changes to the typescript types
Projects
None yet
Development

No branches or pull requests

2 participants