T
TanStack8mo ago
optimistic-gold

TS error "unsafe assignment of type any" using `Route.useParams()`

export const Route = createFileRoute('/_user/learn/$lang/$id')({
component: RouteComponent,
})

function RouteComponent() {
const { lang, id } = Route.useParams()
...
}
export const Route = createFileRoute('/_user/learn/$lang/$id')({
component: RouteComponent,
})

function RouteComponent() {
const { lang, id } = Route.useParams()
...
}
In this case, it seems like my $lang and $id params should be typed automatically (I have registered the router, per these instructions), but I'm still getting this error: "Unsafe assignment of an any value." Any advice? (Copilot says to change the useParams call to Route.useParams<{ lang: string; id: string }>() which actually does fix some of the downstream TS errors, but creates its own TS error and also just seems wrong.)
No description
4 Replies
rising-crimson
rising-crimson8mo ago
can you please provide a complete minimal example?
optimistic-gold
optimistic-goldOP8mo ago
hey @Manuel Schiller , while I was doing this I discovered that the eslint rules for tseslint.plugin.configs['recommended-requiring-type-checking'].rules, were the source of the problem. Now that I've removed this the params correctly destructure with string types inferred as expected. False alarm / thanks.
rising-crimson
rising-crimson8mo ago
great!
optimistic-gold
optimistic-goldOP8mo ago
the same issue was showing up for useSearch (and fixed by removing)

Did you find this page helpful?