File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @ts-rest/nest ' : patch
3+ ---
4+
5+ Allow Nest.js handlers to return non-promise responses
Original file line number Diff line number Diff line change @@ -176,3 +176,5 @@ export type Not<B extends boolean> = {
176176 false : true ;
177177 true : false ;
178178} [ `${B } `] ;
179+
180+ export type Promisable < T > = Promise < T > | T ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import {
3030 isAppRouteOtherResponse ,
3131 parseJsonQueryObject ,
3232 ServerInferResponses ,
33+ Promisable ,
3334} from '@ts-rest/core' ;
3435import {
3536 JsonQuerySymbol ,
@@ -145,12 +146,12 @@ export const TsRestHandler = (
145146
146147type NestHandlerImplementation < T extends AppRouter | AppRoute > =
147148 T extends AppRoute
148- ? ( args : TsRestRequestShape < T > ) => Promise < ServerInferResponses < T > >
149+ ? ( args : TsRestRequestShape < T > ) => Promisable < ServerInferResponses < T > >
149150 : {
150151 [ K in keyof T ] : T [ K ] extends AppRoute
151152 ? (
152153 args : TsRestRequestShape < T [ K ] > ,
153- ) => Promise < ServerInferResponses < T [ K ] > >
154+ ) => Promisable < ServerInferResponses < T [ K ] > >
154155 : never ;
155156 } ;
156157
Original file line number Diff line number Diff line change @@ -3,12 +3,13 @@ import {
33 AppRouter ,
44 Without ,
55 ServerInferResponses ,
6+ Promisable ,
67} from '@ts-rest/core' ;
78import { TsRestRequestShape } from './ts-rest-request.decorator' ;
89
910type AppRouterMethodShape < T extends AppRoute > = (
1011 ...args : any [ ]
11- ) => Promise < ServerInferResponses < T > > ;
12+ ) => Promisable < ServerInferResponses < T > > ;
1213
1314type AppRouterControllerShape < T extends AppRouter > = Without <
1415 {
You can’t perform that action at this time.
0 commit comments