The type of the success value.
The type of the error value.
ReadonlyvalueIf Result.isOk() is true, this is the contained value of type
A. If Result.isErr() is true, this is the error value of type
E.
Given another Result containing a function from A to B:
If both Results are Ok, call the function with the
success value of this Result and return a Result<B, E>
containing what the function returns.
If the result in f is Err, return that instead.
If the result in f is Ok but the original result is
Err, return the original error Result unchanged.
Transform the Result as in Result.chain using one of the two provided functions, according to whether the Result is Ok or Err.
You may notice this is just Result.match with stricter types, to conform to the monadic bind interface.
If the Result is Ok, call the provided function with the contained value and return the result of the function, which must be another Result. If the Result is Err, the Err is returned unchanged and the function is never called.
This is the monadic bind function, for those who celebrate.
Test if the Result is an Err containing a DOMException caused by an AbortController aborting.
A value which can be of either type
Aor typeE.This is normally used as a return value for operations which can fail:
Eis short forError.Acan be thought of as the success value, andEis the error value. This is reflected in their constructors: to construct a success value, you call Ok, and to construct an error value, you call Err.You can also use the Result.await function to convert a Promise that could throw an exception into a Promise that won't throw but instead returns a Result containing either the error or the expected result, or the Result.try function to run a function and catch any exceptions into a Result return value.
Example