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

    Function assert

    • Rust-style assertion that returns a Result instead of throwing.

      Type Parameters

      • E = Error

        The type of the error (defaults to Error)

      Parameters

      • condition: boolean

        The condition to assert

      • error: E = ...

        The error 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 = assert(typeof id === 'string', new Error("ID must be string"))
      if (!check.ok) return check