Skip to content

Can't use type aliases or conditional types resolving to Promise for async/await return types #27987

Open
@tao-cumplido

Description

@tao-cumplido

TypeScript Version: 3.1

Search Terms:

  • async promise alias
  • async promise conditional

Code

type P<T> = Promise<T>

async function foo<T>(x: T): P<T> {
    return x;
}

async function bar<T>(x: T): T extends number ? Promise<number> : Promise<any> {
    return x;
}

Expected behavior:
No error.

Actual behavior:
Type 'P' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.

Type 'T extends number ? Promise : Promise' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.

Playground Link:
Link

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions