I have this code (Playground):
const routes = {
projects: ({}) => "/projects",
"projects.edit": ({ id }: { id: string }) => `/projects/${id}`,
report: ({ projectId }: { projectId: string }) => `/report/${projectId}`,
};
type Routes = typeof routes;
export function generateUrl<Name extends keyof Routes>(
name: Name,
params: Parameters<Routes[Name]>[0]
): string {
const fn = routes[name];
return fn(params);
}
I get this error in line fn(params). How would I write it to type-check (without using any)?
Property 'id' is missing in type '{ projectId: string; }' but required in type '{ id: string; }'.