@@ -448,7 +448,13 @@ export const mapResponse = (
448448 // @ts -expect-error
449449 return handleStream ( response as any , set , request )
450450
451- if ( 'toResponse' in ( response as any ) )
451+ // @ts -expect-error
452+ if ( typeof response ?. then === 'function' )
453+ // @ts -expect-error
454+ return response . then ( ( x ) => mapResponse ( x , set ) ) as any
455+
456+ // @ts -expect-error
457+ if ( typeof response ?. toResponse === 'function' )
452458 return mapResponse ( ( response as any ) . toResponse ( ) , set )
453459
454460 if ( 'charCodeAt' in ( response as any ) ) {
@@ -588,7 +594,13 @@ export const mapResponse = (
588594 // @ts -expect-error
589595 return handleStream ( response as any , set , request )
590596
591- if ( 'toResponse' in ( response as any ) )
597+ // @ts -expect-error
598+ if ( typeof response ?. then === 'function' )
599+ // @ts -expect-error
600+ return response . then ( ( x ) => mapResponse ( x , set ) ) as any
601+
602+ // @ts -expect-error
603+ if ( typeof response ?. toResponse === 'function' )
592604 return mapResponse ( ( response as any ) . toResponse ( ) , set )
593605
594606 if ( 'charCodeAt' in ( response as any ) ) {
@@ -832,8 +844,14 @@ export const mapEarlyResponse = (
832844 // @ts -expect-error
833845 return handleStream ( response as any , set , request )
834846
835- if ( 'toResponse' in ( response as any ) )
836- return mapEarlyResponse ( ( response as any ) . toResponse ( ) , set )
847+ // @ts -expect-error
848+ if ( typeof response ?. then === 'function' )
849+ // @ts -expect-error
850+ return response . then ( ( x ) => mapResponse ( x , set ) ) as any
851+
852+ // @ts -expect-error
853+ if ( typeof response ?. toResponse === 'function' )
854+ return mapResponse ( ( response as any ) . toResponse ( ) , set )
837855
838856 if ( 'charCodeAt' in ( response as any ) ) {
839857 const code = ( response as any ) . charCodeAt ( 0 )
@@ -966,8 +984,14 @@ export const mapEarlyResponse = (
966984 // @ts -expect-error
967985 return handleStream ( response as any , set , request )
968986
969- if ( 'toResponse' in ( response as any ) )
970- return mapEarlyResponse ( ( response as any ) . toResponse ( ) , set )
987+ // @ts -expect-error
988+ if ( typeof response ?. then === 'function' )
989+ // @ts -expect-error
990+ return response . then ( ( x ) => mapResponse ( x , set ) ) as any
991+
992+ // @ts -expect-error
993+ if ( typeof response ?. toResponse === 'function' )
994+ return mapResponse ( ( response as any ) . toResponse ( ) , set )
971995
972996 if ( 'charCodeAt' in ( response as any ) ) {
973997 const code = ( response as any ) . charCodeAt ( 0 )
@@ -1097,8 +1121,14 @@ export const mapCompactResponse = (
10971121 // @ts -expect-error
10981122 return handleStream ( response as any , undefined , request )
10991123
1100- if ( 'toResponse' in ( response as any ) )
1101- return mapCompactResponse ( ( response as any ) . toResponse ( ) )
1124+ // @ts -expect-error
1125+ if ( typeof response ?. then === 'function' )
1126+ // @ts -expect-error
1127+ return response . then ( ( x ) => mapResponse ( x , set ) ) as any
1128+
1129+ // @ts -expect-error
1130+ if ( typeof response ?. toResponse === 'function' )
1131+ return mapResponse ( ( response as any ) . toResponse ( ) , set )
11021132
11031133 if ( 'charCodeAt' in ( response as any ) ) {
11041134 const code = ( response as any ) . charCodeAt ( 0 )
0 commit comments