Function isOk

  • Type guard to check if a Result is an Ok value. This function is used to narrow down the type of a Result to OkResult in TypeScript type system.

    Type Parameters

    • T extends NonUndefined
    • E extends NonUndefined

    Parameters

    • val: Result<T, E>

      The Result to be checked.

    Returns val is OkResult<T, never>

    true if the provided Result is an OkResult, false otherwise.

    const result = Ok('Success');
    if (isOk(result)) {
    console.log('Operation was successful:', result.unwrap());
    }

    Use Result.isOk instead.