@@ -60,9 +60,13 @@ const contract = c.router(
6060 contentType : 'multipart/form-data' ,
6161 body : c . body < { image : File } > ( ) ,
6262 responses : {
63- 201 : z . object ( {
64- id : z . number ( ) ,
65- url : z . string ( ) ,
63+ 201 : c . otherResponse ( {
64+ contentType : 'text/plain' ,
65+ body : c . type < 'Image uploaded successfully' > ( ) ,
66+ } ) ,
67+ 500 : c . otherResponse ( {
68+ contentType : 'text/plain' ,
69+ body : z . literal ( 'Image upload failed' ) ,
6670 } ) ,
6771 } ,
6872 } ,
@@ -85,9 +89,7 @@ const contract = c.router(
8589 } )
8690 ) ,
8791 } ) ,
88- 404 : z . object ( {
89- message : z . string ( ) ,
90- } ) ,
92+ 404 : c . type < null > ( ) ,
9193 } ,
9294 } ,
9395 } ,
@@ -125,16 +127,20 @@ it('type inference helpers', () => {
125127 uploadImage :
126128 | {
127129 status : 201 ;
128- body : { id : number ; url : string } ;
130+ body : 'Image uploaded successfully' ;
129131 }
130- | { status : Exclude < HTTPStatusCode , 201 > ; body : unknown } ;
132+ | {
133+ status : 500 ;
134+ body : 'Image upload failed' ;
135+ }
136+ | { status : Exclude < HTTPStatusCode , 201 | 500 > ; body : unknown } ;
131137 nested : {
132138 getComments :
133139 | {
134140 status : 200 ;
135141 body : { comments : { id : number ; content : string } [ ] } ;
136142 }
137- | { status : 404 ; body : { message : string } }
143+ | { status : 404 ; body : null }
138144 | { status : Exclude < HTTPStatusCode , 200 | 404 > ; body : unknown } ;
139145 } ;
140146 }
@@ -155,17 +161,22 @@ it('type inference helpers', () => {
155161 status : 201 ;
156162 body : { id : number ; title : string ; content : string } ;
157163 } ;
158- uploadImage : {
159- status : 201 ;
160- body : { id : number ; url : string } ;
161- } ;
164+ uploadImage :
165+ | {
166+ status : 201 ;
167+ body : 'Image uploaded successfully' ;
168+ }
169+ | {
170+ status : 500 ;
171+ body : 'Image upload failed' ;
172+ } ;
162173 nested : {
163174 getComments :
164175 | {
165176 status : 200 ;
166177 body : { comments : { id : number ; content : string } [ ] } ;
167178 }
168- | { status : 404 ; body : { message : string } } ;
179+ | { status : 404 ; body : null } ;
169180 } ;
170181 }
171182 >
@@ -191,16 +202,20 @@ it('type inference helpers', () => {
191202 uploadImage :
192203 | {
193204 status : 201 ;
194- body : { id : number ; url : string } ;
205+ body : 'Image uploaded successfully' ;
195206 }
196- | { status : Exclude < HTTPStatusCode , 201 > ; body : unknown } ;
207+ | {
208+ status : 500 ;
209+ body : 'Image upload failed' ;
210+ }
211+ | { status : Exclude < HTTPStatusCode , 201 | 500 > ; body : unknown } ;
197212 nested : {
198213 getComments :
199214 | {
200215 status : 200 ;
201216 body : { comments : { id : number ; content : string } [ ] } ;
202217 }
203- | { status : 404 ; body : { message : string } }
218+ | { status : 404 ; body : null }
204219 | { status : Exclude < HTTPStatusCode , 200 | 404 > ; body : unknown } ;
205220 } ;
206221 }
@@ -271,10 +286,15 @@ it('type inference helpers', () => {
271286 | { status : 404 ; body : { message : string } }
272287 | { status : Exclude < ErrorHttpStatusCode , 404 > ; body : unknown } ;
273288 createPost : { status : ErrorHttpStatusCode ; body : unknown } ;
274- uploadImage : { status : ErrorHttpStatusCode ; body : unknown } ;
289+ uploadImage :
290+ | {
291+ status : 500 ;
292+ body : 'Image upload failed' ;
293+ }
294+ | { status : Exclude < ErrorHttpStatusCode , 500 > ; body : unknown } ;
275295 nested : {
276296 getComments :
277- | { status : 404 ; body : { message : string } }
297+ | { status : 404 ; body : null }
278298 | { status : Exclude < ErrorHttpStatusCode , 404 > ; body : unknown } ;
279299 } ;
280300 }
@@ -295,7 +315,7 @@ it('type inference helpers', () => {
295315 } ;
296316 uploadImage : {
297317 status : 201 ;
298- body : { id : number ; url : string } ;
318+ body : 'Image uploaded successfully' ;
299319 } ;
300320 nested : {
301321 getComments : {
@@ -341,11 +361,16 @@ it('type inference helpers', () => {
341361 uploadImage :
342362 | {
343363 status : 201 ;
344- body : { id : number ; url : string } ;
364+ body : 'Image uploaded successfully' ;
345365 headers : Headers ;
346366 }
347367 | {
348- status : Exclude < HTTPStatusCode , 201 > ;
368+ status : 500 ;
369+ body : 'Image upload failed' ;
370+ headers : Headers ;
371+ }
372+ | {
373+ status : Exclude < HTTPStatusCode , 201 | 500 > ;
349374 body : unknown ;
350375 headers : Headers ;
351376 } ;
@@ -358,7 +383,7 @@ it('type inference helpers', () => {
358383 }
359384 | {
360385 status : 404 ;
361- body : { message : string } ;
386+ body : null ;
362387 headers : Headers ;
363388 }
364389 | {
0 commit comments