FieldedText TypeScript Library
    Preparing search index...

    Type Alias FtResult<T, E>

    FtResult: FtOk<T, E> | FtErr<T, E>

    Represents the outcome of an operation that can either succeed or fail.

    Use this union type to model operations that return either a value or an error. The type is narrowed with Ok.isOk and Err.isErr before reading the payload in each branch.

    Type Parameters

    • T

      The value type produced by a successful operation.

    • E = string

      The error type produced by a failed operation.

    const result: Result<number, string> = Math.random() > 0.5 ? new Ok(42) : new Err("No luck");

    if (result.isOk()) {
    console.log(result.value);
    } else {
    console.error(result.error);
    }