Skip to content

Promise's then method allows to get wrong type for term depends of its type-argument.Β #43642

@Renegatto

Description

@Renegatto

Bug Report

πŸ”Ž Search Terms

then, Promise, async

πŸ•— Version & Regression Information

v 4.2.3
v 4.3.0-dev.20210412

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const foo: Promise<Promise<number>> = 
    Promise.resolve<Promise<number>>(Promise.resolve(666))
//                  ^^^^^^^^^^^^^^^ type argument
foo.then((x: Promise<number>) => console.log(typeof x))
//        ^^^^^^^^^^^^^^^^^ thats actually wrong type for 'x', 'x' is actually a 'number'

πŸ™ Actual behavior

Output: "number"
This is wrong because x annotated as Promise<number> and it typechecks.

πŸ™‚ Expected behavior

Compilation error or output: "object"

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