T
TanStack6mo ago
ratty-blush

Route.useloaderdata() is of type any

Hey all, Getting this very strange issue, I can't even do a repro outside of my codebase, wondering where I should be looking... In the code below, myTables is of type any, despite the route loader clearly returning a number which is typically inferred and should be number. I've tried everything restarting my IDE, doing a fresh dep install, nothing seems to solve this. Whats even more strange is that in the same repo (its a monorepo) I have other projects which are working as expected, but within this package, it doesn't seem to work. Does anyone have any insight into what might be causing this? (Yes createFileRoute is imported)
export const Route = createFileRoute("/")({
component: AccountPage,
loader: async ({ context: { queryClient } }) => {
return 5;
},
});

function AccountPage() {
const myTables = Route.useLoaderData();

return (
<div className="flex flex-col gap-8">
<h2>My tables</h2>

<p></p>
</div>
);
}
export const Route = createFileRoute("/")({
component: AccountPage,
loader: async ({ context: { queryClient } }) => {
return 5;
},
});

function AccountPage() {
const myTables = Route.useLoaderData();

return (
<div className="flex flex-col gap-8">
<h2>My tables</h2>

<p></p>
</div>
);
}
2 Replies
ratty-blush
ratty-blushOP6mo ago
I hate myself, after hours of debugging, I left out one critical piece
// Register the router instance for type safety
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}
// Register the router instance for type safety
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}
xenial-black
xenial-black6mo ago
It be like that sometimes

Did you find this page helpful?