Private
constructorPrivate
errPrivate
okPrivate
setReturns the success value if Result is Ok, otherwise returns the provided default value. This is a safe way to get a value without throwing an error.
The default value to return if Result is Err
Either the success value or the provided default
const success = Result.ok<number, string>(42);
const failure = Result.err<number, string>("error");
success.unwrapOr(0); // returns 42
failure.unwrapOr(0); // returns 0
Static
errCreates a new Result in the Err state with the given error.
The error value
A new Result instance containing the error value
const failure = Result.err<number, string>("invalid input");
Static
okCreates a new Result in the Ok state with the given value.
The success value
A new Result instance containing the success value
const success = Result.ok<number, string>(42);
A Result type that represents either a success (Ok) or failure (Err) state. This is useful for error handling and expressing outcomes that might fail.
Example