Skip to content

Commit 32cf263

Browse files
committed
fix: type of create fetch
1 parent 296a820 commit 32cf263

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@
1818

1919
### ❤️ Contributors
2020

21+
- Bekacru <[email protected]>
22+
23+
## v1.1.2
24+
25+
### Patch
26+
27+
- createFetch return type is now similar to betterFetch
28+
29+
### ❤️ Contributors
30+
2131
- Bekacru <[email protected]>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@better-tools/fetch",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"packageManager": "[email protected]",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.js",

src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface ResponseContext {
1717
response: Response;
1818
}
1919

20-
export interface BaseFetchOptions extends Omit<RequestInit, "body"> {
20+
export interface BetterFetchOptions extends Omit<RequestInit, "body"> {
2121
/**
2222
* a base url that will be prepended to the url
2323
*/
@@ -87,9 +87,9 @@ export interface BaseFetchOptions extends Omit<RequestInit, "body"> {
8787
}
8888

8989
// biome-ignore lint/suspicious/noEmptyInterface: <explanation>
90-
interface CreateFetchOption extends BaseFetchOptions {}
90+
export interface CreateFetchOption extends BetterFetchOptions {}
9191

92-
type FetchOption<T extends Record<string, unknown> = any> = (
92+
export type FetchOption<T extends Record<string, unknown> = any> = (
9393
| {
9494
body?: never;
9595
}
@@ -113,7 +113,7 @@ type FetchOption<T extends Record<string, unknown> = any> = (
113113
body?: T;
114114
}
115115
) &
116-
BaseFetchOptions;
116+
BetterFetchOptions;
117117

118118
type FetchResponse<T, E extends Record<string, unknown> | unknown> =
119119
| {
@@ -269,17 +269,22 @@ export const betterFetch = async <T = any, E = unknown>(
269269
};
270270
};
271271

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, {
276278
...config,
277-
...option,
279+
...options,
278280
});
279281
};
282+
$fetch.native = fetch;
283+
return $fetch;
280284
};
281285

282286
betterFetch.native = fetch;
287+
283288
export type BetterFetch = typeof betterFetch;
284289
export type CreateFetch = typeof createFetch;
285290
export default betterFetch;

0 commit comments

Comments
 (0)