Function: fn()
Wraps a function that may throw and returns a new function that returns a Result or ResultAsync.
You can use either a custom catch handler or rely on the safe: true option
to assume the function cannot throw.
Type Param
The function type to execute (sync or async) or a Promise type.
Type Param
The error type to return if catch is used.
Examples
Call Signature
fn<
T,E>(options): (...args) =>ResultAsync<Awaited<ReturnType<T>>,E>
Type Parameters
T
T extends (...args) => Promise<any>
E
E
Parameters
options
catch
(error) => E
try
T
Returns
(...
args):ResultAsync<Awaited<ReturnType<T>>,E>
Parameters
args
...Parameters<T>
Returns
ResultAsync<Awaited<ReturnType<T>>, E>
Call Signature
fn<
T>(options): (...args) =>ResultAsync<Awaited<ReturnType<T>>,never>
Type Parameters
T
T extends (...args) => Promise<any>
Parameters
options
safe
true
try
T
Returns
(...
args):ResultAsync<Awaited<ReturnType<T>>,never>
Parameters
args
...Parameters<T>
Returns
ResultAsync<Awaited<ReturnType<T>>, never>
Call Signature
fn<
T,E>(options): (...args) =>Result<ReturnType<T>,E>
Type Parameters
T
T extends (...args) => any
E
E
Parameters
options
catch
(error) => E
try
T
Returns
(...
args):Result<ReturnType<T>,E>
Parameters
args
...Parameters<T>
Returns
Result<ReturnType<T>, E>
Call Signature
fn<
T>(options): (...args) =>Result<ReturnType<T>,never>
Type Parameters
T
T extends (...args) => any
Parameters
options
safe
true
try
T
Returns
(...
args):Result<ReturnType<T>,never>
Parameters
args
...Parameters<T>
Returns
Result<ReturnType<T>, never>
