-
Notifications
You must be signed in to change notification settings - Fork 88
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
[Feature request] safeTry
should automatically wrap returned values with ok
#581
Comments
Since current compiler's type narrowing and control flow analysis do not work well with declare const x: 1 | 2
function* g() {
if (x === 1) {
yield* err("XXX").safeUnwrap();
}
x // still typed as `1 | 2`
} So, we need to use return to exit from it. declare const x: 1 | 2
function* g() {
if (x === 1) {
return err("XXX");
}
x // typed as `2`, as expected
} It is common behavior for So, for now, I don't think it's a good idea to wrap the returned value automatically. |
@tsuburin Agree, this makes sense as a 1-2 punch. Has this been raised as a separate issue? |
I found this. |
@tsuburin I meant in this repo, since returning |
@mattpocock Oh, sorry. As far as I know, it hasn't. |
Problem
One awkward thing about
.safeTry
is that it requires you to wrap everything returned in aResult
.This gets particularly awkward when
safeTry
is modelling a function that returnsvoid
.Solution
I propose that
safeTry
should automatically wrap returned values withok
.This would make
safeTry
returningvoid
perfectly fine:Existing
safeTry
functions returningok
orerr
would still be respected.This matches the behaviour found in Effect.gen.
The text was updated successfully, but these errors were encountered: