T
TanStack6mo ago
optimistic-gold

useParams returns any

Hi everyone,
export const Route = createFileRoute("/myRoute/$id")({
component: MyComponent,
});

function MyComponent() {
const { id } = Route.useParams();
...
}
export const Route = createFileRoute("/myRoute/$id")({
component: MyComponent,
});

function MyComponent() {
const { id } = Route.useParams();
...
}
TypeScript: Unsafe assignment of an 'any' value Do you know why this is happening? I tried tweaking the configuration, read through the useParams docs, and got nothing. Additionally, I remember that in other projects the returned parameter was of type string. What could be going on?
2 Replies
robust-apricot
robust-apricot6mo ago
make sure to register the router type as shown in the docs also do you have strict null check activated in tsconfig.json ? if all this does not help, please provide a minimal complete example
optimistic-gold
optimistic-goldOP6mo ago
Thanks, I didn't register the router type. https://tanstack.com/router/v1/docs/framework/react/api/router/RegisterType Solved
Register type | TanStack Router React Docs
This type is used to register a route tree with a router instance. Doing so unlocks the full type safety of TanStack Router, including top-level exports from the @tanstack/react-router package. tsx ex...

Did you find this page helpful?