-
Notifications
You must be signed in to change notification settings - Fork 12
The catch method of Promise
seems unreasonable
#32
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
Comments
Yes, this was intentional. It matches the type signature of the catch :: Exception e => IO a -> (e -> IO a) -> IO a
You can still do that. You just need to be explicit about the type of the awaited value. @@ -1,4 +1,4 @@
async function main() {
- const value = await Promise.resolve('1').catch(() => undefined);
+ const value = await Promise.resolve<string | undefined>('1').catch(() => undefined);
// ^? const value: string | undefiend
}
The impl<T> Option<T> {
pub fn unwrap_or(self, default: T) -> T {…}
}
Agreed. You should always provide a callback function to That being said, I wouldn't mind making the callback function of
In my humble opinion, using a different type for the result of |
@uinz Please consider closing this issue if my response solved your problem or was helpful in finding a solution to your problem. |
The original Promise method will union the result of resolve with the result of catch
But now the
catch
signature must return the same type as resolve.In my opinion
await task().catch(() => defaultValue)
is a good development experienceSimilar to rust's
unwrap_or
In addition, I think onrejected as optional will also bring some ambiguity.
The
.catch()
of the following code is actually uselessTherefore, I suggest modifying it as follows
The text was updated successfully, but these errors were encountered: