@@ -17,7 +17,7 @@ interface ResponseContext {
17
17
response : Response ;
18
18
}
19
19
20
- export interface BaseFetchOptions extends Omit < RequestInit , "body" > {
20
+ export interface BetterFetchOptions extends Omit < RequestInit , "body" > {
21
21
/**
22
22
* a base url that will be prepended to the url
23
23
*/
@@ -87,9 +87,9 @@ export interface BaseFetchOptions extends Omit<RequestInit, "body"> {
87
87
}
88
88
89
89
// biome-ignore lint/suspicious/noEmptyInterface: <explanation>
90
- interface CreateFetchOption extends BaseFetchOptions { }
90
+ export interface CreateFetchOption extends BetterFetchOptions { }
91
91
92
- type FetchOption < T extends Record < string , unknown > = any > = (
92
+ export type FetchOption < T extends Record < string , unknown > = any > = (
93
93
| {
94
94
body ?: never ;
95
95
}
@@ -113,7 +113,7 @@ type FetchOption<T extends Record<string, unknown> = any> = (
113
113
body ?: T ;
114
114
}
115
115
) &
116
- BaseFetchOptions ;
116
+ BetterFetchOptions ;
117
117
118
118
type FetchResponse < T , E extends Record < string , unknown > | unknown > =
119
119
| {
@@ -269,17 +269,22 @@ export const betterFetch = async <T = any, E = unknown>(
269
269
} ;
270
270
} ;
271
271
272
- export const createFetch = < Error = unknown > ( config ?: CreateFetchOption ) => {
273
- return async < T = any , E = undefined > ( url : string , option ?: FetchOption ) => {
274
- type ResponseError = E extends undefined ? Error : E ;
275
- return await betterFetch < T , ResponseError > ( url , {
272
+ export const createFetch = ( config ?: CreateFetchOption ) => {
273
+ const $fetch = async < T = any , E = unknown > (
274
+ url : string | URL ,
275
+ options ?: FetchOption ,
276
+ ) : Promise < FetchResponse < T , E > > => {
277
+ return await betterFetch < T , E > ( url , {
276
278
...config ,
277
- ...option ,
279
+ ...options ,
278
280
} ) ;
279
281
} ;
282
+ $fetch . native = fetch ;
283
+ return $fetch ;
280
284
} ;
281
285
282
286
betterFetch . native = fetch ;
287
+
283
288
export type BetterFetch = typeof betterFetch ;
284
289
export type CreateFetch = typeof createFetch ;
285
290
export default betterFetch ;
0 commit comments