-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add PromiseResult type to standard lib #28105
Copy link
Copy link
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript