T
TanStack5mo ago
correct-apricot

Typing a factory function for createFileRoute

Hello everyone, I am trying to create a factory function that returns a createFileRoute with some options predefined, but I am not able to type it correctly with all the generics. Here is an example what I am trying to accomplish:
function customCreateFileRoute(path) {
return (options) => {
return createFileRoute(path)({
...options,
staticData: {
title: 'Test',
...options.staticData,
},
})
}
}
function customCreateFileRoute(path) {
return (options) => {
return createFileRoute(path)({
...options,
staticData: {
title: 'Test',
...options.staticData,
},
})
}
}
Can someone help me with the correct types? Thanks in advance.
6 Replies
apparent-cyan
apparent-cyan5mo ago
it won't work at compile time with automatic code splitting though we currently don't support abstractions on top of createFileRoute
correct-apricot
correct-apricotOP5mo ago
So I guess the best alternative way to accomplish this is to pass all the predefined options to each createFileRoute separately?
const defaultStaticData = {
title: 'Test',
} as const

createFileRoute('/test')({
staticData: {
...defaultStaticData
},
})
const defaultStaticData = {
title: 'Test',
} as const

createFileRoute('/test')({
staticData: {
...defaultStaticData
},
})
apparent-cyan
apparent-cyan5mo ago
yes
correct-apricot
correct-apricotOP5mo ago
And are there any plans of supporting this kind of abstractions? I have quite a lot of routes with the same options, so it would be much better to use that way
apparent-cyan
apparent-cyan5mo ago
it's in my wishlist but quite involved due to the static analysis the compiler needs to do for this not a high priority right now
correct-apricot
correct-apricotOP5mo ago
ok, looking forward for that. thank you

Did you find this page helpful?