This PR proposes two Type-Guards, allowing to safely access error or value of a Result.
This should improve the Ergonomics of the Result-API.
hasValue
// instead of
if (result.isSuccess) {
const value = result.getValueOrThrow();
}
// do
if (result.hasValue()) {
const value = result.value; // value is accessible because the type-guard has been executed before
}
hasError
// instead of
if (result.isFailure) {
const error = result.getErrorOrThrow();
}
// do
if (result.hasError()) {
const error= result.error; // erroris accessible because the type-guard has been executed before
}
This PR proposes two Type-Guards, allowing to safely access error or value of a Result. This should improve the Ergonomics of the Result-API.
hasValue
hasError
Some notes
isSuccess
andisFailure
to methods would introduce a breaking change.isSuccess()
directly. Maybe this could be a breaking change for the next major release.