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

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