T
TanStack2y ago
absent-sapphire

Type assignment flip in LoaderFnContext

I'm trying to build own types on top of the Tanstack router because my router collects it's routes at runtime and application is federated (spread across different packages); and while generally speaking it's a complicated task due to type safety, there's one problem I'm running into over and over again. In LoaderFnContext, if you try to do something like RouteCollector<TRoute extends MyAppAnyRoute = MyAppAnyRoute> it works well until reaches that type in shouldReload. At this moment, it tries to reverse-validate that my MyAppAnyRoute satisfies the exact route that I'm declared. It's like intentionally at some point tries to assign AnyMatch to the declared ExactMatch. Any ideas why it may happen?
No description
1 Reply
absent-sapphire
absent-sapphireOP2y ago
MyAppAnyRoute is basically AnyRoute but with MyAppRouteContext and MyAppRouterContext assigned. Any when I add something like test: () => 'test' to my beforeLoad, i.e. declare it as a part of the context, it fails to resolve types because it's now tries to do MyAppAnyRoute extends TRoute instead of TRoute extends MyAppAnyRoute inside that LoaderFnContext And even if I do MyAppRouteContext = AnyContext & MyAppOwnRouteContext it's still the same, I thought maybe it's unable to expand my context I think I start to undestand what happens there, it tries to verify that what I return is compliant with MyAppAnyRoute, but it cannot exntend the MyAppContext in it for some reason.

Did you find this page helpful?