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

Defer generic awaited type #34883

Closed
wants to merge 2 commits into from
Closed

Defer generic awaited type #34883

wants to merge 2 commits into from

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Nov 2, 2019

async function f<T>(x: T) {
    return x;
}
const result: Promise<number> = f(undefined as Promise<number>);

Before

!!! error TS2322: Type 'Promise<Promise<number>>' is not assignable to type 'Promise<number>'.
!!! error TS2322:   Type 'Promise<number>' is not assignable to type 'number'.

After

getConditionalType() defers the awaited type until the generic type is instantiated, if it might or might not be promise like.

Fixes #27711

@typescript-bot test this
@typescript-bot run dt
@typescript-bot user test this

@jablko jablko force-pushed the patch-21 branch 2 times, most recently from d33a51b to f4f67e6 Compare November 16, 2019 15:24
@jablko jablko force-pushed the patch-21 branch 5 times, most recently from 5c3717e to 31db2c4 Compare November 28, 2019 14:51
@jablko jablko force-pushed the patch-21 branch 3 times, most recently from d7fb48d to ac90de3 Compare January 25, 2020 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promise<Promise<T>> cannot exist in JS
2 participants