Possible type exhaustion with dependency injection?
Just checking if anyone else has ran into these TS errors from the router. Nothing critical, with no rush or urgency on this, as I'm still running the app fine without dependency injection.
Is anyone doing dependency injection of the react-query QueryClient in something larger with a multi-file routes setup?
I'm currently storing a decent bit of state in the query-params, and when I set the RouterContext generic to
{queryClient: typeof queryClient} it then loses the types of the queryParams in the <Link /> component and also triggers some Type instantiation is excessively deep and possibly infinite. errors.

7 Replies
unwilling-turquoiseOP•3y ago
Link component current showing up as implicitly any

unwilling-turquoiseOP•3y ago
Tsconfig setup
unwilling-turquoiseOP•3y ago
For context this is on
0.0.1-beta.134absent-sapphire•3y ago
I'm getting this as well without any route context: https://discord.com/channels/719702312431386674/1007702008448426065/1128992825984438352
This is just a gut feeling, but I don't think it is triggered by any specific aspect of the router, but just because of all the type inference when your application becomes larger.
I saw Tanner was exploring some typescript performance optimizations in the #router channel, so I'm hoping this might help in a future release.
unwilling-turquoiseOP•3y ago
@vixducis not sure if it was a change in 139, but when I added the
queryClient via the RouterContext via this method, I stopped getting those type exhaustion errors.
For whatever reason, when I define an interface and pass it into the RouterContext, it doesn't have a problem with it, vs directly adding the type into the generic.
unwilling-turquoiseOP•3y ago
Only thought of doing this because I happened to be going through the documentation 🤦
https://tanstack.com/router/v1/docs/guide/router-context#typed-router-context
Router Context | TanStack Router Docs
TanStack Router's router context is a very powerful tool that can be used for dependency injection among many other things. Aptly named, the router context is passed through the router and down through each matching route. At each route in the hierarchy, the context can be modified or added to. Here's a few ways you might use the router context...
absent-sapphire•3y ago
I'm not using any RouterContext, so the problem couldn't be there on my end.