T
TanStack6mo ago
deep-jade

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
flat-fuchsia
flat-fuchsia6mo ago
can you please provide a complete minimal example?
deep-jade
deep-jadeOP6mo 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.
flat-fuchsia
flat-fuchsia6mo ago
great!
deep-jade
deep-jadeOP6mo ago
the same issue was showing up for useSearch (and fixed by removing)

Did you find this page helpful?