Skip to content

Promise.catch should have a return type of <TResult>, not T. #3834

Closed
@MicahZoltu

Description

@MicahZoltu

Current implementaiton:

interface Promise<T> {
    then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
    then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;

    catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
}

What I believe is a more correct implementation:

interface Promise<T> {
    then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
    then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;

    catch<TResult>(onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
    catch<TResult>(onrejected?: (reason: any) => void): Promise<TResult>;
}

I believe the spec says that catch(x) behaves the same as then(undefined, x), which implies that catch should be a generic method with a TResult type.

If I am misunderstanding the spec, enlightenment would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions