Feature Request: Add _unsafeUnwrap() and _unsafeUnwrapErr() to ResultAsync
Problem
Result provides two test utilities for quickly unwrapping values in test environments:
result._unsafeUnwrap() // returns T or throws
result._unsafeUnwrapErr() // returns E or throws
ResultAsync has no equivalent. Users must always await first and then call the methods on the resolved Result, which is more verbose in tests:
// Current — two steps required
const res = await myResultAsync
const value = res._unsafeUnwrap()
// Desired — one step
const value = await myResultAsync._unsafeUnwrap()
Impact
This asymmetry is particularly annoying in test code where you're doing many assertions on ResultAsync values. Every assertion requires an intermediate await before you can check the value.
Suggested Implementation
// In ResultAsync class
async _unsafeUnwrap(config?: ErrorConfig): Promise<T> {
return this._promise.then((res) => res._unsafeUnwrap(config))
}
async _unsafeUnwrapErr(config?: ErrorConfig): Promise<E> {
return this._promise.then((res) => res._unsafeUnwrapErr(config))
}
This mirrors the existing unwrapOr pattern already on ResultAsync:
unwrapOr<A>(t: A): Promise<T | A> {
return this._promise.then((res) => res.unwrapOr(t))
}
Consistency Table
| Method |
Result |
ResultAsync |
unwrapOr() |
✅ |
✅ |
match() |
✅ |
✅ |
_unsafeUnwrap() |
✅ |
❌ |
_unsafeUnwrapErr() |
✅ |
❌ |
Feature Request: Add
_unsafeUnwrap()and_unsafeUnwrapErr()toResultAsyncProblem
Resultprovides two test utilities for quickly unwrapping values in test environments:ResultAsynchas no equivalent. Users must alwaysawaitfirst and then call the methods on the resolvedResult, which is more verbose in tests:Impact
This asymmetry is particularly annoying in test code where you're doing many assertions on
ResultAsyncvalues. Every assertion requires an intermediateawaitbefore you can check the value.Suggested Implementation
This mirrors the existing
unwrapOrpattern already onResultAsync:Consistency Table
ResultResultAsyncunwrapOr()match()_unsafeUnwrap()_unsafeUnwrapErr()