镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Promise of type { } ignored when nested #13008

Description

TypeScript Version: 2.1.4

Code

function getDate(): Promise<Date> {
    return Promise.resolve(new Date());
}

function getFoo(): Promise<{}> {
    return Promise.resolve({});
}

function doFoo() : Promise<number> {

    // Error: Type 'Promise<Date>' is not assignable to type 'Promise<number>'.
    return (
        getDate()
            .then(() => {

                return (
                    getFoo()
                        .then(() => {

                            return 10;
                        })
                );
            })
    );
}

Expected behavior:

No compilation error

Actual behavior:

Compiler error: Type 'Promise<Date>' is not assignable to type 'Promise<number>'.

Futher Notes
Changing getFoo to return any other value, e.g. function getFoo(): Promise<void> fixes the compilation error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions