diff --git a/src/client/types.ts b/src/client/types.ts index 30f8140ce0..c53c3aabd6 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -245,17 +245,21 @@ export type FilterClientResponseByStatusCode< : never : never +// Helper type to strip leading slashes without recursion in PathToChain +type StripLeadingSlash = T extends `/${infer P}` ? StripLeadingSlash

: T + type PathToChain< Prefix extends string, Path extends string, E extends Schema, Original extends string = Path, -> = Path extends `/${infer P}` - ? PathToChain - : Path extends `${infer P}/${infer R}` +> = + StripLeadingSlash extends `${infer P}/${infer R}` ? { [K in P]: PathToChain } : { - [K in Path extends '' ? 'index' : Path]: ClientRequest< + [K in StripLeadingSlash extends '' + ? 'index' + : StripLeadingSlash]: ClientRequest< Prefix, Original, E extends Record ? E[Original] : never