Skip to content

Promise.catch should allow to widen promise type #57

Closed
@danielrentz

Description

@danielrentz

Promise.catch can be used to silence rejections and to make the result optional by converting rejections to undefined (or more generally, to add any other result type to the promise chain). This is not possible anymore with better-ts-lib:

// before (TS lib)
const promise1 = Promise.resolve("a").then(() => 42, () => undefined);  // Promise<number | undefined>
const promise2 = Promise.resolve(42).catch(() => undefined);            // Promise<number | undefined>

// after (better-ts-lib)
const promise1 = Promise.resolve("a").then(() => 42, () => undefined);  // Promise<number | undefined>
const promise2 = Promise.resolve(42).catch(() => undefined);            // <=== type error

Could you add a catch<U> similar to the existing then<U>?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions