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 of promise type is somehow possible #26839

Closed
KSXGitHub opened this issue Sep 2, 2018 · 4 comments
Closed

Promise of promise type is somehow possible #26839

KSXGitHub opened this issue Sep 2, 2018 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@KSXGitHub
Copy link
Contributor

TypeScript Version: 3.0.0

Search Terms:

Code

async function fn<X>(x: X) {
    return await x
}

const foo = fn(123) // Promise<number>
const bar = fn(foo) // Promise<Promise<number>>
const baz = fn(Promise.resolve('abc')) // Promise<Promise<string>>

Expected behavior:

bar and baz should be Promise<number> and Promise<string> respectively.

Actual behavior:

They are Promise<Promise<number>> and Promise<Promise<string>>

Playground Link: link

Related Issues:

@j-oliveras
Copy link
Contributor

Workaround:

async function fn<X>(x: PromiseLike<X>): Promise<X> // You can change PromiseLike to Promise
async function fn<X>(x: X): Promise<X>
async function fn<X>(x: X) {
    return await x
}

const foo = fn(123) // Promise<number>
const bar = fn(foo) // Promise<number>
const baz = fn(Promise.resolve('abc')) // Promise<string>

Playground.

@j-oliveras
Copy link
Contributor

Simplified workaround:

async function fn<X>(x: PromiseLike<X> | X) {
    return await x
}

const foo = fn(123) // Promise<number>
const bar = fn(foo) // Promise<number>
const baz = fn(Promise.resolve('abc')) // Promise<string>

Playground.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Sep 17, 2018
@DanielRosenwasser
Copy link
Member

I just triaged #27711 so forwarding to that.

@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels Oct 25, 2018
@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

6 participants