diff --git a/packages/express-typed/package.json b/packages/express-typed/package.json index 3a2e147..1aaae27 100644 --- a/packages/express-typed/package.json +++ b/packages/express-typed/package.json @@ -1,6 +1,6 @@ { "name": "express-typed", - "version": "0.0.3", + "version": "0.1.0", "description": "", "type": "module", "main": "dist/express-typed.js", diff --git a/packages/express-typed/src/express-typed.ts b/packages/express-typed/src/express-typed.ts index 5b6ea49..f002dd8 100644 --- a/packages/express-typed/src/express-typed.ts +++ b/packages/express-typed/src/express-typed.ts @@ -13,7 +13,6 @@ export type IHandlerResponse = { jsonp(arg: T): IHandlerResponse<[...Res, { jsonp: T }]>; send(arg: T): IHandlerResponse<[...Res, { send: T }]>; } & Response; - export type SendMethod = "send" | "json" | "jsonp"; export type IHandlerRequest = {} & Request; @@ -32,7 +31,7 @@ export class TypedRouter< [key in HandlerMethods]?: (req: IHandlerRequest, res: IHandlerResponse, next: NextFunction) => void; } | TypedRouter; - } + }, > { router: express.Router; routes: R; @@ -59,7 +58,7 @@ export type FlatNestedRouters = { ? ( x: T[K] extends TypedRouter ? FlatNestedRouters<{ [K2 in keyof N extends string ? `${keyof N}` : "" as `${K}${K2}`]: N[K2] }> - : Pick + : Pick, ) => void : never; } extends { [k: string]: (x: infer I) => void } @@ -71,7 +70,7 @@ export type UnionToIntersection = (U extends any ? (x: U) => void : never) ex export type GetRouteResponseInfoHelper< Router extends TypedRouter["routes"], Path extends keyof FlatNestedRouters, - Method extends keyof FlatNestedRouters[Path] + Method extends keyof FlatNestedRouters[Path], > = UnionToIntersection< ( ReturnType< @@ -88,13 +87,13 @@ export type GetRouteResponseInfo< Router extends TypedRouter["routes"], Path extends keyof FlatNestedRouters, Method extends keyof FlatNestedRouters[Path], - Info extends keyof GetRouteResponseInfoHelper | "body" = "body" + Info extends keyof GetRouteResponseInfoHelper | "body" = "body", // Info extends "body" | undefined = undefined > = Info extends "body" ? GetRouteResponseInfoHelper[Extract, SendMethod>] : Info extends keyof GetRouteResponseInfoHelper - ? GetRouteResponseInfoHelper[Info] - : GetRouteResponseInfoHelper; + ? GetRouteResponseInfoHelper[Info] + : GetRouteResponseInfoHelper; export type ParseRoutes> = FlatNestedRouters;