Unwraps a Result, returning the value if it is Ok. Throws the error if it is an Err.
Result
Ok
Err
The Result to unwrap.
The value if res is Ok.
res
The error if res is Err.
const result = Ok("Success!");const value = unwrapResult(result); // "Success!"const errorResult = Err(new Error("Oops!"));unwrapResult(errorResult); // throws Error: "Oops!" Copy
const result = Ok("Success!");const value = unwrapResult(result); // "Success!"const errorResult = Err(new Error("Oops!"));unwrapResult(errorResult); // throws Error: "Oops!"
Unwraps a
Result, returning the value if it isOk. Throws the error if it is anErr.