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 codeThis wouldn't change the runtime behavior of existing JavaScript codeThis could be implemented without emitting different JS based on the types of the expressionsThis isn't a runtime feature (e.g. new expression-level syntax)
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
DanielRosenwasser commentedon Oct 24, 2018
See #17077, and discussion at
Search also for
awaited
,await
,promised
,unpromise
, andunpromisify
on the issue tracker.DanielRosenwasser commentedon Oct 24, 2018
Just to clarify, for
Promises
to work correctly we need a more generalawaited
type which unwrapsPromiseLike
s recursively. If we had that, it would subsume thisPromiseResult
type.ajafff commentedon Oct 24, 2018
Sounds like recursive conditional types to me... but that's already discussed somewhere else
deser commentedon Dec 12, 2019
Any progress here? :)
westonkjones commentedon Dec 19, 2019
Interested in this as well. The AWS SDK uses this as the return of their promises
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SecretsManager.html#getSecretValue-property
fregante commentedon Jan 11, 2020
Coming in #35998, hopefully