Skip to content

Conversation

@jeremylvln
Copy link

Hi!

Some of my tests needs to prepare some context by calling methods returning Results. These methods are already well-tested, I do not want to bother to check again for Ok or Error. Having these shortcut helpers would help me simplify the tests.

Pretty similar to Rust's unwrap() methods.

Copy link
Contributor

@bloodyowl bloodyowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello!

thanks for contributing, I added a small comment. for consistency can you also add this to the AsyncData class (it shares the same structural concept)?

*/
getOrThrow(this: Result<A, E>): A | never {
if (this.tag === "Error") {
throw new Error("Tried to unwrap a Result.Error value");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd throw this.error directly in this case, or at least put it in the error's cause.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea, I wanted to use cause, unfortunately it is not supported yet by the Typescript version used in the project.

Now throwing this.error if the error is string. Also added the implementation for AsyncData

@jeremylvln jeremylvln requested a review from bloodyowl July 29, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants