Why isn't my context typed
I'm trying to figure out why my context is not typed, I seem to have set up everything like suggested in the documentation

12 Replies
sensitive-blue•6mo ago
do you use
createRootRouteWithContext in __root ?optimistic-goldOP•6mo ago
No, my __root is createRootRout
should it be with context?
sensitive-blue•6mo ago
yes
since you want ... context 😄
sensitive-blue•6mo ago
createRootRouteWithContext function | TanStack Router React Docs
The createRootRouteWithContext function is a helper function that can be used to create a root route instance that requires a context type to be fulfilled when the router is created. createRootRouteWi...
optimistic-goldOP•6mo ago
I see but I don't understand how that would affect the type other files
sensitive-blue•6mo ago
be aware of the extra
()optimistic-goldOP•6mo ago
if I log the context in my routes it has the context but it's just not typed appropriately
sensitive-blue•6mo ago
the type for the router context needs to come from somewhere
and createRootRouteWithContext is the way to provide that type
optimistic-goldOP•6mo ago
Hmm ok so I changed it to
createRootRouteWithContext but the types are still not in my other other file routes
when I hover the return type of create router I get something like this
sensitive-blue•6mo ago
did you specify the generic?
optimistic-goldOP•6mo ago
Ok I see, so the generic has to be passed into createRootRouteWithContext
I thought the context could be infered from what values you passed into context when using createTanstackRouter
It's working now, thank you!
sensitive-blue•6mo ago
no unfortunately not
that's the one place where you need to actually write typescript in router 😄