@@ -93,22 +93,39 @@ export type _TypedFetch<OP> = (
9393 init ?: RequestInit ,
9494) => Promise < ApiResponse < OpReturnType < OP > > >
9595
96- export type _TypedFetchOptional < OP > = OpArgType < OP > extends Record <
97- PropertyKey ,
98- never
99- >
100- ? (
101- arg ?: OpArgType < OP > ,
102- init ?: RequestInit ,
103- ) => Promise < ApiResponse < OpReturnType < OP > > >
104- : _TypedFetch < OP >
96+ export type _OptionalTypedFetch < OP > = (
97+ arg ?: OpArgType < OP > ,
98+ init ?: RequestInit ,
99+ ) => Promise < ApiResponse < OpReturnType < OP > > >
100+
101+ // export type _TypedFetchOptional<OP> = OpArgType<OP> extends Record<
102+ // PropertyKey,
103+ // never
104+ // >
105+ // ? _OptionalTypedFetch<OP>
106+ // : _TypedFetch<OP>
105107
106- export type TypedFetch < OP > = _TypedFetchOptional < OP > & {
108+ export type TypedFetch < OP > = _TypedFetch < OP > & {
107109 Error : new ( error : ApiError ) => ApiError & {
108110 getActualType : ( ) => OpErrorType < OP >
109111 }
110112}
111113
114+ export type TypedFetchOptional < OP > = OpArgType < OP > extends Record <
115+ PropertyKey ,
116+ never
117+ >
118+ ? _OptionalTypedFetch < OP > & {
119+ Error : new ( error : ApiError ) => ApiError & {
120+ getActualType : ( ) => OpErrorType < OP >
121+ }
122+ }
123+ : _TypedFetch < OP > & {
124+ Error : new ( error : ApiError ) => ApiError & {
125+ getActualType : ( ) => OpErrorType < OP >
126+ }
127+ }
128+
112129export type FetchArgType < F > = F extends TypedFetch < infer OP >
113130 ? OpArgType < OP >
114131 : never
@@ -357,7 +374,7 @@ async function fetchUrl<R>(request: Request) {
357374 } ) ) as ApiResponse < R >
358375}
359376
360- function createFetch < OP > ( fetch : _TypedFetchOptional < OP > ) : TypedFetch < OP > {
377+ function createFetch < OP > ( fetch : _TypedFetch < OP > ) : TypedFetchOptional < OP > {
361378 const fun = async ( payload : OpArgType < OP > , init ?: RequestInit ) => {
362379 try {
363380 return await fetch ( payload , init )
@@ -382,7 +399,7 @@ function createFetch<OP>(fetch: _TypedFetchOptional<OP>): TypedFetch<OP> {
382399 }
383400 }
384401
385- return fun
402+ return fun as TypedFetchOptional < OP >
386403}
387404
388405function fetcher < Paths > ( ) {
0 commit comments