@@ -129,6 +129,7 @@ export type RequestOptions<T> = ParamsOption<T> &
129129 pathSerializer ?: PathSerializer ;
130130 parseAs ?: ParseAs ;
131131 fetch ?: ClientOptions [ "fetch" ] ;
132+ Request ?: typeof Request ;
132133 headers ?: HeadersOptions ;
133134 middleware ?: Middleware [ ] ;
134135 } ;
@@ -195,6 +196,8 @@ export type MaybeOptionalInit<Params, Location extends keyof Params> =
195196 ? FetchOptions < FilterKeys < Params , Location > > | undefined
196197 : FetchOptions < FilterKeys < Params , Location > > ;
197198
199+ type InitWithParseAs < Init , P extends ParseAs | undefined > = Init & ( P extends ParseAs ? { parseAs : P } : { } ) ;
200+
198201// The final init param to accept.
199202// - Determines if the param is optional or not.
200203// - Performs arbitrary [key: string] addition.
@@ -206,25 +209,25 @@ export type ClientMethod<
206209 Paths extends Record < string , Record < HttpMethod , { } > > ,
207210 Method extends HttpMethod ,
208211 Media extends MediaType ,
209- > = < Path extends PathsWithMethod < Paths , Method > , Init extends MaybeOptionalInit < Paths [ Path ] , Method > > (
212+ > = < Path extends PathsWithMethod < Paths , Method > , P extends ParseAs | undefined = undefined > (
210213 url : Path ,
211- ...init : InitParam < Init >
212- ) => Promise < FetchResponse < Paths [ Path ] [ Method ] , Init , Media > > ;
214+ ...init : InitParam < InitWithParseAs < MaybeOptionalInit < Paths [ Path ] , Method > , P > >
215+ ) => Promise < FetchResponse < Paths [ Path ] [ Method ] , InitWithParseAs < MaybeOptionalInit < Paths [ Path ] , Method > , P > , Media > > ;
213216
214217export type ClientRequestMethod < Paths extends Record < string , Record < HttpMethod , { } > > , Media extends MediaType > = <
215218 Method extends HttpMethod ,
216219 Path extends PathsWithMethod < Paths , Method > ,
217- Init extends MaybeOptionalInit < Paths [ Path ] , Method > ,
220+ P extends ParseAs | undefined = undefined ,
218221> (
219222 method : Method ,
220223 url : Path ,
221- ...init : InitParam < Init >
222- ) => Promise < FetchResponse < Paths [ Path ] [ Method ] , Init , Media > > ;
224+ ...init : InitParam < InitWithParseAs < MaybeOptionalInit < Paths [ Path ] , Method > , P > >
225+ ) => Promise < FetchResponse < Paths [ Path ] [ Method ] , InitWithParseAs < MaybeOptionalInit < Paths [ Path ] , Method > , P > , Media > > ;
223226
224227export type ClientForPath < PathInfo extends Record < string | number , any > , Media extends MediaType > = {
225- [ Method in keyof PathInfo as Uppercase < string & Method > ] : < Init extends MaybeOptionalInit < PathInfo , Method > > (
226- ...init : InitParam < Init >
227- ) => Promise < FetchResponse < PathInfo [ Method ] , Init , Media > > ;
228+ [ Method in keyof PathInfo as Uppercase < string & Method > ] : < P extends ParseAs | undefined = undefined > (
229+ ...init : InitParam < InitWithParseAs < MaybeOptionalInit < PathInfo , Method > , P > >
230+ ) => Promise < FetchResponse < PathInfo [ Method ] , InitWithParseAs < MaybeOptionalInit < PathInfo , Method > , P > , Media > > ;
228231} ;
229232
230233export interface Client < Paths extends { } , Media extends MediaType = MediaType > {
0 commit comments