@@ -11,7 +11,7 @@ import {
11
11
useQuery ,
12
12
useSuspenseQuery ,
13
13
} from "@tanstack/react-query" ;
14
- import type { ClientMethod , FetchResponse , MaybeOptionalInit , Client as FetchClient } from "openapi-fetch" ;
14
+ import type { ClientMethod , FetchResponse , MaybeOptionalInit , Client as FetchClient , ClientPathsWithMethod } from "openapi-fetch" ;
15
15
import type { HttpMethod , MediaType , PathsWithMethod , RequiredKeysOf } from "openapi-typescript-helpers" ;
16
16
17
17
type InitWithUnknowns < Init > = Init & { [ key : string ] : unknown } ;
@@ -93,6 +93,16 @@ export interface OpenapiQueryClient<Paths extends {}, Media extends MediaType =
93
93
useMutation : UseMutationMethod < Paths , Media > ;
94
94
}
95
95
96
+ export type MethodResponse <
97
+ CreatedClient extends OpenapiQueryClient < any , any > ,
98
+ Method extends HttpMethod ,
99
+ Path extends ClientPathsWithMethod < FetchClient < any , any > , Method > ,
100
+ Options = { }
101
+ > =
102
+ CreatedClient extends OpenapiQueryClient < infer Paths extends { [ key : string ] : any } , infer Media extends MediaType >
103
+ ? NonNullable < FetchResponse < Paths [ Path ] [ Method ] , Options , Media > [ "data" ] >
104
+ : never
105
+
96
106
// TODO: Add the ability to bring queryClient as argument
97
107
export default function createClient < Paths extends { } , Media extends MediaType = MediaType > (
98
108
client : FetchClient < Paths , Media > ,
@@ -141,3 +151,4 @@ export default function createClient<Paths extends {}, Media extends MediaType =
141
151
) ,
142
152
} ;
143
153
}
154
+
0 commit comments