diff --git a/examples/express-typed-prisma/.env b/examples/express-typed-prisma/.env new file mode 100644 index 0000000..c498ab5 --- /dev/null +++ b/examples/express-typed-prisma/.env @@ -0,0 +1,7 @@ +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +DATABASE_URL="file:./dev.db" \ No newline at end of file diff --git a/packages/express-typed/src/express-typed.ts b/packages/express-typed/src/express-typed.ts index 3735994..57e5273 100644 --- a/packages/express-typed/src/express-typed.ts +++ b/packages/express-typed/src/express-typed.ts @@ -57,7 +57,6 @@ export class TypedRouter< } } - // extract any relevant information from TypedRouter, and flatten any nested routers export type ParseRoutes> = FlatNestedRouters; @@ -88,9 +87,9 @@ export type GetRouteResponseInfoHelper< Method extends keyof Router[Path] > = UnionToIntersection< ( - ReturnType< - Router[Path][Method] extends (...args: any) => any ? Router[Path][Method] : never - > extends TypedResponse + ReturnType any ? Router[Path][Method] : never> extends + | TypedResponse + | Promise> ? Res : never ) extends (infer U)[] @@ -120,7 +119,7 @@ export type GetRouteResponseInfo< * Get all the keys in the router that have a specific method * for example, KeysWithMethod might return "/" | "/nested" */ -export type KeysWithMethod['routes'], Method extends GetRouterMethods> = { +export type KeysWithMethod["routes"], Method extends GetRouterMethods> = { [K in keyof Router]: Method extends keyof Router[K] ? K : never; }[keyof Router]; @@ -128,14 +127,12 @@ export type KeysWithMethod['routes'], Method ext * Get all the existing methods for any endpoint in the router * for example, GetRouterMethods might return "get" | "post" | "all" or something similar, if those are the methods are defined on some of the endpoints in the router */ -export type GetRouterMethods['routes']> = keyof UnionToIntersection; +export type GetRouterMethods["routes"]> = keyof UnionToIntersection; /** * Get all the routes in the router that have a specific method * for example, GetRoutesWithMethod might return { "/": "Hello world", "/nested": "get /nested/" } */ -export type GetRoutesWithMethod['routes'], Method extends GetRouterMethods> = { - [Path in KeysWithMethod]: Method extends keyof Router[Path] - ? GetRouteResponseInfo - : never; +export type GetRoutesWithMethod["routes"], Method extends GetRouterMethods> = { + [Path in KeysWithMethod]: Method extends keyof Router[Path] ? GetRouteResponseInfo : never; };