Skip to content

Add PromiseResult type to standard lib #28105

@ethanresnick

Description

@ethanresnick

Search Terms

promise result type

Suggestion

Typescript already ships with a ReturnType type and a Parameters type, so why not ship with a PromiseResult type:

type PromiseResult<T> = T extends Promise<infer U> ? U : never;

Use Cases/Examples

type Output = PromiseResult<ReturnType<typeof computeSomething>>;

async function computeSomething(input: any) {}
function computeFromResult(input: Output) {}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions