Skip to content

awaiting a Promise recasts top variable to initial type #19918

Closed
@bondz

Description

@bondz

TypeScript Version: 2.6.1, 2.7.0-dev.20171110

function test(a: boolean): false | Date {
    if (a) {
        return new Date();
    }

    return false;
}


async function test2() {
    let b = test(true);

    if (!b) {
        b = new Date();
    }
    
    await Promise.all([]).then(() => {
        b.getDate(); //Should compile.
            
    })
}

Expected behavior:
Should compile
Actual behavior:
Throws with Property 'getDate' does not exist on type 'true'.


This can be reproduced with any return type and even when type inference is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions