I need to define a TypeScript type in the following format:
type Route =
Record<string, string> & { buildUrl: (params: Record<string, string>) => string }
An example object of this type would be:
const route: Route = {
base: 'dashboard',
section: ':sectionId',
tab1: 'overview',
tab2: 'settings',
buildUrl: ({ sectionId, tab }) => `/dashboard/${sectionId}/${tab}`,
}
Multiple instances of these Route
objects will exist, each with their own unique keys and buildUrl
function.
Is there a way to create a type that permits this structure? Any guidance is appreciated.