Closed
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)