Skip to content

Suggestion: Implied Promise return type in async functions #7284

Closed
@nevir

Description

@nevir

Apologies if this has already been brought up, but I wasn't able to find any issues that cover this topic (#5911 seems closest).

The Current State

Currently, if you want to enforce typing of an async function's resolved value, you must declare a return type of :Promise<ResolveType>:

async function makeStuff():Promise<Stuff> {}

This is a bit counterintuitive when it comes to async functions, as they generally mask the fact that there's a Promise there to begin with. If you are utilizing promises purely via async/await, you're never going to see the token Promise in your code.

Proposal

When providing the return type of an async function, implicitly wrap it in a Promise<T> (unless it is an explicit Promise<T> type expression?). This seems reasonable now that #6631 is in.

async function makeStuff():Stuff {}

Seems like the least surprising way of declaring an async function

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions