@jenova-marie/ts-rust-result - v2.2.18
    Preparing search index...

    Function assertOr

    • Rust-style assertion with a typed error parameter.

      Type Parameters

      • E

        The type of the error

      Parameters

      • condition: boolean

        The condition to assert

      • error: E

        The error object to return if the condition is false

      • shouldThrow: boolean = true

        Whether to throw the error instead of returning a Result (defaults to true)

      Returns Result<true, E>

      A Result that is ok(true) if condition is true, or err(error) if false

      If shouldThrow is true and condition is false

      const check = assertOr(
      user.isAdmin,
      new PermissionError("Admin access required")
      )
      if (!check.ok) return check