Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use type guards for isOk/isFail in Result #174

Merged
merged 1 commit into from
Jun 14, 2021
Merged

fix: use type guards for isOk/isFail in Result #174

merged 1 commit into from
Jun 14, 2021

Conversation

IgnusG
Copy link
Contributor

@IgnusG IgnusG commented Jun 13, 2021

Hello, just found your library and was trying it out when I noticed the results weren't making use of typescript's type guards so I wanted to propose a small change to support them.

This ensures that:

const a = new OkResult("ok") as Result<string, string>;

if (a.isOk()) {
  const b = a; // Both a and b are narrowed to OkResult;
}

// a is Result outside of the block

Same for isFail

This ensures that: `if (a.isOk()) { /* a will narrow to OkResult inside this block */ }`
Same for isFail
@patrickmichalina
Copy link
Owner

@IgnusG excellent, thank you!

@patrickmichalina patrickmichalina merged commit 037e802 into patrickmichalina:master Jun 14, 2021
@patrickmichalina
Copy link
Owner

🎉 This PR is included in version 6.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants