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

    Function unwrap

    • Unwraps a Result, returning the value if successful or throwing the error if failed.

      Type Parameters

      • T

        The type of the successful value

      • E = Error

        The type of the error

      Parameters

      • result: Result<T, E>

        The Result to unwrap

      Returns T

      The value if the Result is successful

      If the Result is an error, throws the error

      const result = ok("hello world")
      const value = unwrap(result) // "hello world"

      const errorResult = err(new Error("Something went wrong"))
      try {
      const value = unwrap(errorResult) // Throws the error
      } catch (error) {
      console.error(error.message) // "Something went wrong"
      }