Skip to content

True Myth / result / ResultConstructor

Interface: ResultConstructor ​

The public interface for the Result class as a value: the static constructors ok and err produce a Result with that variant.

Properties ​

err ​

err: {<T, _E>(): Result<T, Unit>; <T, E>(error): Result<T, E>; }

Call Signature ​

<T, _E>(): Result<T, Unit>

Create an instance of Err.

ts
const anErr = Result.err('alas, failure');
Type Parameters ​
T ​

T = never

_E ​

_E = unknown

Returns ​

Result<T, Unit>

Call Signature ​

<T, E>(error): Result<T, E>

Create an instance of Err.

ts
const anErr = Result.err('alas, failure');
Type Parameters ​
T ​

T = never

E ​

E = unknown

Parameters ​
error ​

E

The value to wrap in an Err.

Returns ​

Result<T, E>


ok ​

ok: {(): Result<Unit, never>; <T, E>(value): Result<T, E>; }

Call Signature ​

(): Result<Unit, never>

Create an instance of Ok.

Note that you may explicitly pass Unit to the ok constructor to create a Result<Unit, E>. However, you may not call the ok constructor with null or undefined to get that result (the type system won't allow you to construct it that way). Instead, for convenience, you can simply call `Result.ok()`, which will construct the type correctly.

Returns ​

Result<Unit, never>

Call Signature ​

<T, E>(value): Result<T, E>

Type Parameters ​
T ​

T

E ​

E = never

Parameters ​
value ​

T

The value to wrap in an Ok.

Returns ​

Result<T, E>