Skip to content

Defer generic awaited type - #34883

Closed
Jack Bates (jablko) wants to merge 2 commits into
microsoft:masterfrom
jablko:patch-21
Closed

Defer generic awaited type#34883
Jack Bates (jablko) wants to merge 2 commits into
microsoft:masterfrom
jablko:patch-21

Conversation

@jablko

Copy link
Copy Markdown
Contributor
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 (@typescript-bot) test this
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) user test this

@typescript-bot

Copy link
Copy Markdown
Contributor

The TypeScript team hasn't accepted the linked issue #27711. If you can get it accepted, this PR will have a better chance of being reviewed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

3 participants