Wraps a function execution (sync or async) or a Promise in a Result or ResultAsync type, capturing errors and returning them in a structured way.
You can use either a custom catch
handler or rely on the safe: true
option
to assume the function cannot throw.
The function type to execute (sync or async) or a Promise type.
The error type to return if catch
is used.
try<
T
,E
>(options
):ResultAsync
<Awaited
<T
>,E
>
Defined in: functions/try.ts:98
T
extends Promise
<any
>
E
(error
) => E
T
ResultAsync
<Awaited
<T
>, E
>
try<
T
>(options
):ResultAsync
<Awaited
<T
>,never
>
Defined in: functions/try.ts:101
T
extends Promise
<any
>
true
T
ResultAsync
<Awaited
<T
>, never
>
try<
T
,E
>(options
): (...args
) =>ResultAsync
<Awaited
<ReturnType
<T
>>,E
>
Defined in: functions/try.ts:104
T
extends (...args
) => Promise
<any
>
E
(error
) => E
T
(...
args
):ResultAsync
<Awaited
<ReturnType
<T
>>,E
>
...Parameters
<T
>
ResultAsync
<Awaited
<ReturnType
<T
>>, E
>
try<
T
>(options
): (...args
) =>ResultAsync
<Awaited
<ReturnType
<T
>>,never
>
Defined in: functions/try.ts:107
T
extends (...args
) => Promise
<any
>
true
T
(...
args
):ResultAsync
<Awaited
<ReturnType
<T
>>,never
>
...Parameters
<T
>
ResultAsync
<Awaited
<ReturnType
<T
>>, never
>
try<
T
,E
>(options
): (...args
) =>Result
<ReturnType
<T
>,E
>
Defined in: functions/try.ts:110
T
extends (...args
) => any
E
(error
) => E
T
(...
args
):Result
<ReturnType
<T
>,E
>
...Parameters
<T
>
Result
<ReturnType
<T
>, E
>
try<
T
>(options
): (...args
) =>Result
<ReturnType
<T
>,never
>
Defined in: functions/try.ts:113
T
extends (...args
) => any
true
T
(...
args
):Result
<ReturnType
<T
>,never
>
...Parameters
<T
>
Result
<ReturnType
<T
>, never
>