Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Renegatto opened this issue Apr 12, 2021 Β· 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Renegatto
Copy link

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"

@MartinJohns
Copy link
Contributor

MartinJohns commented Apr 12, 2021 β€’

Duplicate of #27711. Promise<Promise<T>> should result in an error.

Your initial foo type is already wrong. It should be Promise<number>.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Apr 12, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants