Setu-TS
    Preparing search index...

    Type Alias Result<T, E>

    Result: Ok<T> | Err<E>

    The result of an operation that can fail: either Ok or Err. Narrow with the success discriminant or the isOk/isErr guards.

    Type Parameters

    • T

      The success value type

    • E = Error

      The error type (defaults to Error)

    function parsePort(raw: string): Result<number, RangeError> {
    const port = Number(raw);
    return Number.isInteger(port) && port > 0 && port < 65536
    ? ok(port)
    : err(new RangeError(`Invalid port: ${raw}`));
    }

    const result = parsePort('3000');
    if (result.success) {
    listen(result.value);
    }

    0.1.0