11type Branded < T > = T & { __tryCatchTupleResult : any } ;
22type 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
1515type 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
6666export 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