Skip to content

Commit 61346c9

Browse files
author
jarvisjiang
committed
the error type returned by a non-abortable fetch is explicitly Error
1 parent da56324 commit 61346c9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/fetch/defines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { AsyncResult, IOResult } from 'happy-rusty';
66
*
77
* @typeParam T - The type of the data expected in the response.
88
*/
9-
export type FetchResponse<T> = AsyncResult<T, any>;
9+
export type FetchResponse<T, E = any> = AsyncResult<T, E>;
1010

1111
/**
1212
* Defines the structure and behavior of a fetch task, including the ability to abort the task and check its status.

src/fetch/fetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function fetchT<T>(url: string | URL, init: FetchInit & {
6262
*/
6363
export function fetchT(url: string | URL, init: FetchInit & {
6464
responseType: 'text';
65-
}): FetchResponse<string>;
65+
}): FetchResponse<string, Error>;
6666

6767
/**
6868
* Fetches a resource from the network as an ArrayBuffer and returns a `FetchResponse` representing the operation.
@@ -73,7 +73,7 @@ export function fetchT(url: string | URL, init: FetchInit & {
7373
*/
7474
export function fetchT(url: string | URL, init: FetchInit & {
7575
responseType: 'arraybuffer';
76-
}): FetchResponse<ArrayBuffer>;
76+
}): FetchResponse<ArrayBuffer, Error>;
7777

7878
/**
7979
* Fetches a resource from the network as a Blob and returns a `FetchResponse` representing the operation.
@@ -84,7 +84,7 @@ export function fetchT(url: string | URL, init: FetchInit & {
8484
*/
8585
export function fetchT(url: string | URL, init: FetchInit & {
8686
responseType: 'blob';
87-
}): FetchResponse<Blob>;
87+
}): FetchResponse<Blob, Error>;
8888

8989
/**
9090
* Fetches a resource from the network and parses it as JSON, returning a `FetchResponse` representing the operation.
@@ -96,7 +96,7 @@ export function fetchT(url: string | URL, init: FetchInit & {
9696
*/
9797
export function fetchT<T>(url: string | URL, init: FetchInit & {
9898
responseType: 'json';
99-
}): FetchResponse<T>;
99+
}): FetchResponse<T, Error>;
100100

101101
/**
102102
* Fetches a resource from the network and returns a `FetchTask` representing the operation with a generic `Response`.

0 commit comments

Comments
 (0)