File tree Expand file tree Collapse file tree 3 files changed +66
-6
lines changed Expand file tree Collapse file tree 3 files changed +66
-6
lines changed Original file line number Diff line number Diff line change
1
+ # 1.2.25 - 6 Mar 2025
2
+ Bug fix:
3
+ - [ #1108 ] ( https://github.com/elysiajs/elysia/issues/1108 ) use validation response instead of return type when schema is provided
4
+
1
5
# 1.2.24 - 2 Mar 2025
2
6
Bug fix:
3
7
- 200 object response is not inferring type in type-level
Original file line number Diff line number Diff line change @@ -1537,12 +1537,16 @@ export type EmptyRouteSchema = {
1537
1537
1538
1538
type _ComposeElysiaResponse < Schema extends RouteSchema , Handle > = Prettify <
1539
1539
Prettify <
1540
- {
1541
- 200 : Exclude < Handle , ElysiaCustomStatusResponse < any , any , any > >
1542
- } & ExtractErrorFromHandle < Handle > &
1543
- ( { } extends Schema [ 'response' ]
1544
- ? { }
1545
- : Omit < Schema [ 'response' ] , 200 > ) &
1540
+ ( Schema [ 'response' ] extends { 200 : any }
1541
+ ? { }
1542
+ : {
1543
+ 200 : Exclude <
1544
+ Handle ,
1545
+ ElysiaCustomStatusResponse < any , any , any >
1546
+ >
1547
+ } ) &
1548
+ ExtractErrorFromHandle < Handle > &
1549
+ ( { } extends Schema [ 'response' ] ? { } : Schema [ 'response' ] ) &
1546
1550
( EmptyRouteSchema extends Schema
1547
1551
? { }
1548
1552
: {
Original file line number Diff line number Diff line change @@ -2246,3 +2246,55 @@ type a = keyof {}
2246
2246
}
2247
2247
} )
2248
2248
}
2249
+
2250
+ // Use validation response instead of return type
2251
+ {
2252
+ const app = new Elysia ( ) . get (
2253
+ '/' ,
2254
+ ( ) => {
2255
+ return {
2256
+ name : 'a' ,
2257
+ a : 'b'
2258
+ }
2259
+ } ,
2260
+ {
2261
+ response : {
2262
+ 200 : t . Object ( {
2263
+ name : t . String ( )
2264
+ } ) ,
2265
+ 400 : t . Object ( {
2266
+ name : t . String ( )
2267
+ } )
2268
+ }
2269
+ }
2270
+ )
2271
+
2272
+ expectTypeOf < ( typeof app . _routes . index . get . response ) [ 200 ] > ( ) . toEqualTypeOf < {
2273
+ name : string
2274
+ } > ( )
2275
+ }
2276
+
2277
+ // Use return type when validation is not provided
2278
+ {
2279
+ const app = new Elysia ( ) . get (
2280
+ '/' ,
2281
+ ( ) => {
2282
+ return {
2283
+ name : 'a' ,
2284
+ a : 'b'
2285
+ }
2286
+ } ,
2287
+ {
2288
+ response : {
2289
+ 400 : t . Object ( {
2290
+ name : t . String ( )
2291
+ } )
2292
+ }
2293
+ }
2294
+ )
2295
+
2296
+ expectTypeOf < ( typeof app . _routes . index . get . response ) [ 200 ] > ( ) . toEqualTypeOf < {
2297
+ name : string
2298
+ a : string
2299
+ } > ( )
2300
+ }
You can’t perform that action at this time.
0 commit comments