Unwraps a Result, returning the value if successful or throwing the error if failed.
The type of the successful value
The type of the error
The Result to unwrap
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"} Copy
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"}
Unwraps a Result, returning the value if successful or throwing the error if failed.