Skip to content

Promise can be resolved with undefined but not reflected in type #11094

Closed
@OliverJAsh

Description

@OliverJAsh

TS 2.0.3

    new Promise<string>(resolve => {
        true ? resolve('foo') :  resolve()
    })

This returns a Promise<string>, however it is possible to call resolve with no value, meaning the return type is actually Promise<string | undefined> at runtime.

I'm not sure whether the return type should in fact be inferred as Promise<string | undefined> or whether the empty resolve() call should throw a compile error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions