@@ -93,22 +93,39 @@ export type _TypedFetch<OP> = (
93
93
init ?: RequestInit ,
94
94
) => Promise < ApiResponse < OpReturnType < OP > > >
95
95
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>
105
107
106
- export type TypedFetch < OP > = _TypedFetchOptional < OP > & {
108
+ export type TypedFetch < OP > = _TypedFetch < OP > & {
107
109
Error : new ( error : ApiError ) => ApiError & {
108
110
getActualType : ( ) => OpErrorType < OP >
109
111
}
110
112
}
111
113
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
+
112
129
export type FetchArgType < F > = F extends TypedFetch < infer OP >
113
130
? OpArgType < OP >
114
131
: never
@@ -357,7 +374,7 @@ async function fetchUrl<R>(request: Request) {
357
374
} ) ) as ApiResponse < R >
358
375
}
359
376
360
- function createFetch < OP > ( fetch : _TypedFetchOptional < OP > ) : TypedFetch < OP > {
377
+ function createFetch < OP > ( fetch : _TypedFetch < OP > ) : TypedFetchOptional < OP > {
361
378
const fun = async ( payload : OpArgType < OP > , init ?: RequestInit ) => {
362
379
try {
363
380
return await fetch ( payload , init )
@@ -382,7 +399,7 @@ function createFetch<OP>(fetch: _TypedFetchOptional<OP>): TypedFetch<OP> {
382
399
}
383
400
}
384
401
385
- return fun
402
+ return fun as TypedFetchOptional < OP >
386
403
}
387
404
388
405
function fetcher < Paths > ( ) {
0 commit comments