Skip to content

ResultAsync missing _unsafeUnwrap() and _unsafeUnwrapErr() test utilities #681

Description

@Binilkks

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions