import { compile } from 'path-to-regexp'; type PathParams = TPath extends `${string}:${infer TParam}/${infer TRest}` ? (TParam extends `${infer U}?` ? U : TParam) | PathParams : TPath extends `${string}:${infer TParam}` ? TParam extends `${infer U}?` ? U : TParam : never; export function generatePath(path: TPath, params?: Partial, string>>): string { return compile(path, { encode: encodeURIComponent })(params); }