Skip to content

wrong type inference in Promise #31266

Closed
@dislido

Description

@dislido

TypeScript Version: 3.4.3

Search Terms:

Code

let foo: string | undefined;
if (!foo) foo = 'hello';

foo.length; // ok

new Promise(resolve => resolve(foo.length));
//                              ^ should be string, but inferred as string | undefined

Expected behavior:

Actual behavior:

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions