Type Alias Result<T, E>

Result:
    | { error?: never; ok: true; value: T }
    | { error: E; ok: false; value?: never }

A monad that captures the result of a function call or an error if it was not successful. Railway programming, enabled by this type, can be a nicer alternative to traditional exception throwing because it allows functions to declare all known errors with static types and then check for them exhaustively in application code. Thrown exception have a type of unknown and break out of regular control flow of programs making them harder to inspect and more verbose work with due to try-catch blocks.

Type Parameters

  • T
  • E = unknown