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
conscious-sapphire•3mo ago
do you use
createRootRouteWithContext
in __root
?extended-salmonOP•3mo ago
No, my __root is createRootRout
should it be with context?
conscious-sapphire•3mo ago
yes
since you want ... context 😄
conscious-sapphire•3mo 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...
extended-salmonOP•3mo ago
I see but I don't understand how that would affect the type other files
conscious-sapphire•3mo ago
be aware of the extra
()
extended-salmonOP•3mo ago
if I log the context in my routes it has the context but it's just not typed appropriately
conscious-sapphire•3mo ago
the type for the router context needs to come from somewhere
and createRootRouteWithContext is the way to provide that type
extended-salmonOP•3mo 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
conscious-sapphire•3mo ago
did you specify the generic?
extended-salmonOP•3mo 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!
conscious-sapphire•3mo ago
no unfortunately not
that's the one place where you need to actually write typescript in router 😄