-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
The original Promise method will union the result of resolve with the result of catch
async function main() {
const value = await Promise.resolve("1").catch(() => undefined);
// ^? const value: string | undefiend
}
But now the catch
signature must return the same type as resolve.
interface Promise<T> {
// ...
catch(
onrejected?: ((reason: unknown) => T | PromiseLike<T>) | null | undefined
): Promise<T>;
}
In my opinion await task().catch(() => defaultValue)
is a good development experience
Similar to rust's unwrap_or
const value = await task().catch(() => defaultValue)
In addition, I think onrejected as optional will also bring some ambiguity.
The .catch()
of the following code is actually useless
const value = awiat task().catch()
Therefore, I suggest modifying it as follows
interface Promise<T> {
// ...
catch<R>(
onrejected: ((reason: unknown) => R | PromiseLike<R>)
): Promise<T | R>;
}
uhyo and aaditmshah
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working