Skip to content

Commit e26c833

Browse files
committed
chore: update default error type
1 parent b26904c commit e26c833

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/try-catch-tuple/src/tryCatch.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
type Branded<T> = T & { __tryCatchTupleResult: any };
22
type Success<T> = Branded<[data: T, error: null]>;
3-
type Failure<E> = Branded<[data: null, error: E | Error]>;
4-
type Result<T, E> = Success<T> | Failure<E>;
3+
type Failure<E extends Error> = Branded<[data: null, error: E | Error]>;
4+
type Result<T, E extends Error> = Success<T> | Failure<E>;
55

6-
type TryCatchResult<T, E> = T extends Promise<infer U>
6+
type TryCatchResult<T, E extends Error> = T extends Promise<infer U>
77
? Promise<Result<U, E>>
88
: Result<T, E>;
99

10-
type TryCatchFunc<E_ extends Error = never> = <T, E extends Error = E_>(
10+
type TryCatchFunc<E_ extends Error = Error> = <T, E extends Error = E_>(
1111
fn?: T | (() => T),
1212
operationName?: string,
1313
) => TryCatchResult<T, E>;
1414

1515
type TryCatch<
1616
F extends TryCatchFunc = TryCatchFunc,
17-
E_ extends Error = never,
17+
E_ extends Error = Error,
1818
> = F & {
1919
sync: <T, E extends Error = E_>(
2020
fn: () => T,
@@ -35,7 +35,7 @@ type TryCatch<
3535
* @param operationName Optional name for context.
3636
* @returns A Result, or a Promise resolving to a Result, depending on fn.
3737
*/
38-
export const tryCatch: TryCatch = <T, E extends Error = never>(
38+
export const tryCatch: TryCatch = <T, E extends Error = Error>(
3939
fn?: T | (() => T),
4040
operationName?: string,
4141
) => {
@@ -51,7 +51,7 @@ export const tryCatch: TryCatch = <T, E extends Error = never>(
5151
}
5252
};
5353

54-
export const tryCatchSync: TryCatch["sync"] = <T, E extends Error = never>(
54+
export const tryCatchSync: TryCatch["sync"] = <T, E extends Error = Error>(
5555
fn: () => T,
5656
operationName?: string,
5757
) => {
@@ -65,7 +65,7 @@ export const tryCatchSync: TryCatch["sync"] = <T, E extends Error = never>(
6565

6666
export const tryCatchAsync: TryCatch["async"] = async <
6767
T,
68-
E extends Error = never,
68+
E extends Error = Error,
6969
>(
7070
fn: Promise<T> | (() => Promise<T>),
7171
operationName?: string,

0 commit comments

Comments
 (0)