T
TanStack7mo ago
deep-jade

weird type stuff trying to wrap `createFileRoute`

basically i'm just trying to create a tiny utility that sets ssr: false by default on my route definitions. the types in router are pretty crazy, so i'm trying to use typescript helpers to do most of this. i have something that seems as though it should work, but for some reason I'm getting weird ts errors about circular dependencies and definitions referencing themselves
export function createFileRouteWithoutSSR(path: keyof FileRoutesByPath) {
const addRouteConfig = createFileRoute(path);

type Options = Parameters<typeof addRouteConfig>[0];

const invokeAddRouteConfig = (options: Options) => {
return addRouteConfig({
ssr: false,
...options,
});
};

return invokeAddRouteConfig;
}
export function createFileRouteWithoutSSR(path: keyof FileRoutesByPath) {
const addRouteConfig = createFileRoute(path);

type Options = Parameters<typeof addRouteConfig>[0];

const invokeAddRouteConfig = (options: Options) => {
return addRouteConfig({
ssr: false,
...options,
});
};

return invokeAddRouteConfig;
}
addRouteConfig is giving me 'addRouteConfig' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022) type Options is giving me Type alias 'Options' circularly references itself any ideas? this is sort of start-adjacent, but this would be a nice thing to have so i don't have to set this in every route
1 Reply
rival-black
rival-black7mo ago
you cannot create abstractions on top do createaFileRoute. at least yet I want this but unsure how to implement

Did you find this page helpful?