Skip to content

asTry

asTry<T>(x): AsTry<T>

Take an expression and evaluate it. When the expression throws it will be converted to a Try Failure.

Example

asTry("foobar")
// => "foobar"
asTry(() => "foobar")
// => "foobar"
asTry(async () => "foobar")
// => Promise<"foobar">

Type Parameters

T extends unknown

The expression type.

Parameters

x

T

The expression to evaluate.

Returns

AsTry<T>

The unpacked value.