Interface ResultConstructor

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

interface ResultConstructor {
    err: {
        <T = never, E = never>(): Result<T, Unit>;
        <T = never, E = never>(error: E): Result<T, E>;
    };
    ok: {
        <T extends {}, E = never>(): Result<Unit, E>;
        <T, E = never>(value: T): Result<T, E>;
    };
}

Properties

Properties

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

Type declaration

    • <T = never, E = never>(): Result<T, Unit>
    • Create an instance of Err.

      Note: While you may create the Result type via normal JavaScript class construction, it is not recommended for the functional style for which the library is intended. Instead, use err.

      // Avoid:
      const anErr = new Result.Err('alas, failure');

      // Prefer:
      const anErr = Result.err('alas, failure');

      Type Parameters

      • T = never
      • E = never

      Returns Result<T, Unit>

    • <T = never, E = never>(error: E): Result<T, E>
    • Create an instance of Err.

      Note: While you may create the Result type via normal JavaScript class construction, it is not recommended for the functional style for which the library is intended. Instead, use err.

      // Avoid:
      const anErr = new Result.Err('alas, failure');

      // Prefer:
      const anErr = Result.err('alas, failure');

      Type Parameters

      • T = never
      • E = never

      Parameters

      • error: E

        The value to wrap in an Err.

      Returns Result<T, E>

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

Type declaration

    • <T extends {}, E = never>(): Result<Unit, E>
    • Create an instance of Ok.

      Note: While you may create the Result type via normal JavaScript class construction, it is not recommended for the functional style for which the library is intended. Instead, use ok.

      // Avoid:
      const aString = new Result.Ok('characters');

      // Prefer:
      const aString = Result.ok('characters);

      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 ok, which will construct the type correctly.

      Type Parameters

      • T extends {}
      • E = never

      Returns Result<Unit, E>

    • <T, E = never>(value: T): Result<T, E>
    • Create an instance of Ok.

      Note: While you may create the Result type via normal JavaScript class construction, it is not recommended for the functional style for which the library is intended. Instead, use ok.

      // Avoid:
      const aString = new Result.Ok('characters');

      // Prefer:
      const aString = Result.ok('characters);

      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 ok, which will construct the type correctly.

      Type Parameters

      • T
      • E = never

      Parameters

      • value: T

        The value to wrap in an Ok.

      Returns Result<T, E>