regexparam
regexparam copied to clipboard
RouteParams for route with both required and multiple optional parameters gives incorrect typing
With RouteParams<'/leagues/:routeId/:slugStr?/:subPage?'> the inferred types seem to parse the route incorrectly.
Expected:
{
routeId: string;
slugStr?: string | undefined;
subPage?: string | undefined;
}
Actual:
{
"routeId/slugStr"?: string | undefined;
subPage?: string | undefined;
}
This is TS 5.6.2 if that makes a difference
It doesn't seem like this package is being actively maintained, so if anyone has the same bug:
declare module 'regexparam' {
type RouteParams<T extends string> =
T extends `${infer Prev}/*/${infer Rest}`
? RouteParams<Prev> & { wild: string } & RouteParams<Rest>
: T extends `${string}:${infer P}/${infer Rest}`
? P extends `${infer S}?`
? { [K in S]?: string } & RouteParams<Rest>
: { [K in P]: string } & RouteParams<Rest>
: T extends `${string}:${infer P}?`
? { [K in P]?: string }
: T extends `${string}:${infer P}`
? { [K in P]: string }
: T extends `${string}*`
? { '*': string }
: T extends `${string}*?`
? { '*'?: string }
: {};
...
}
Updated using an override declaration file, rather than patch-package; easy since it's only 4 types to reimplement.