type RouteTypeMap = { string: string; number: number; boolean: boolean; any: any; }; type ResolveRouteType = T extends keyof RouteTypeMap ? RouteTypeMap[T] : any; type TrimRoute = S extends ` ${infer R}` ? TrimRoute : S extends `${infer L} ` ? TrimRoute : S; type RequiredParams = S extends `${string}{${infer Body}}${infer Rest}` ? Body extends `${string}?:${string}` ? RequiredParams : Body extends `${infer K}:${infer T}` ? { [P in TrimRoute]: ResolveRouteType>>; } & RequiredParams : RequiredParams : unknown; type OptionalParams = S extends `${string}{${infer Body}}${infer Rest}` ? Body extends `${infer K}?:${infer T}` ? { [P in TrimRoute]?: ResolveRouteType>> | null; } & OptionalParams : OptionalParams : unknown; type Prettify = { [K in keyof T]: T[K]; } & {}; /** * Extracts a typed params object from a route template literal. * * @example * RouteParams<"/api/Todo/{id: number}"> * // -> { id: number } * RouteParams<"/api/Todos?{$search?: string}&{$pageSize?: number}"> * // -> { $search?: string | null; $pageSize?: number | null } */ export type ControllerRouteParams = Prettify & OptionalParams>; type ControllerInstance = T extends abstract new (...args: Array) => infer TInstance ? TInstance : T; /** * Resolves a controller (class or instance type) to the route it is declared for, read from the * phantom `__route` brand that `QueryController`/`CommandController` carry via their `TRoute` type * parameter. Falls back to `string` for controllers that don't declare a specific route. */ export type ControllerRoute = ControllerInstance extends { readonly __route?: infer TRoute extends string; } ? TRoute : string; export {}; //# sourceMappingURL=route-params.d.ts.map