Skip to content

tryToError

tryToError<T>(x): T extends Failure ? never : Success<T>

Convert the Try to a its value, where Success is converted to the value, and Failure is thrown`.

Example

tryToError("foobar")
// => "foobar"
tryToError(new Error("foobar"))
// => throw Error("foobar")

Type Parameters

T extends unknown

The value type.

Parameters

x

T

The Try to transform.

Returns

T extends Failure ? never : Success<T>