diff --git a/src/types/routeMethods.ts b/src/types/routeMethods.ts index 19b606fd..a571982b 100644 --- a/src/types/routeMethods.ts +++ b/src/types/routeMethods.ts @@ -58,9 +58,9 @@ export type ExtractRouteMethodParams = T extends RouteMethod export type ExtractParamsFromPath< TPath extends Route['path'] > = TPath extends Path - ? ExtractParamsFromPathString, TPath['params']> + ? TPath['params'] : TPath extends string - ? ExtractParamsFromPathString> + ? Path['params'] : never type ParamEnd = '/' @@ -71,12 +71,12 @@ type UnifyParamEnds< export type ExtractParamsFromPathString< TPath extends string, - TParams extends Record = Record -> = TPath extends `${infer Path}${ParamEnd}` + TParams extends Record = Record +> = UnifyParamEnds extends `${infer Path}${ParamEnd}` ? ExtractParamsFromPathString - : TPath extends `${string}:${infer Param}${ParamEnd}${infer Rest}` + : UnifyParamEnds extends `${string}:${infer Param}${ParamEnd}${infer Rest}` ? MergeParams<{ [P in ExtractParamName]: ExtractPathParamType }, ExtractParamsFromPathString> - : TPath extends `${string}:${infer Param}` + : UnifyParamEnds extends `${string}:${infer Param}` ? { [P in ExtractParamName]: ExtractPathParamType } : Record @@ -115,7 +115,7 @@ type ExtractParamName< type ExtractPathParamType< TParam extends string, - TParams extends Record + TParams extends Record > = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? ExtractParamType | undefined @@ -124,7 +124,7 @@ type ExtractPathParamType< ? ExtractParamType : string -type ExtractParamType = TParam extends ParamGetSet +type ExtractParamType = TParam extends ParamGetSet ? Type : TParam extends ParamGetter ? ReturnType diff --git a/src/utilities/path.ts b/src/utilities/path.ts index fad39fd4..e3e723b8 100644 --- a/src/utilities/path.ts +++ b/src/utilities/path.ts @@ -11,7 +11,7 @@ export type Path< P extends PathParams = any > = { path: T, - params: P, + params: Identity>, } export function path>(_path: T, _params: Identity

): Path {