promise result type
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;
type Output = PromiseResult<ReturnType<typeof computeSomething>>;
async function computeSomething(input: any) {}
function computeFromResult(input: Output) {}
My suggestion meets these guidelines:
See #17077, and discussion at
Search also for awaited, await, promised, unpromise, and unpromisify on the issue tracker.
Just to clarify, for Promises to work correctly we need a more general awaited type which unwraps PromiseLikes recursively. If we had that, it would subsume this PromiseResult type.
Just to clarify, for Promises to work correctly we need a more general awaited type which unwraps PromiseLikes recursively.
Sounds like recursive conditional types to me... but that's already discussed somewhere else
Any progress here? :)
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
(method) Request<SecretsManager.GetSecretValueResponse, AWSError>.promise(): Promise<PromiseResult<AWS.SecretsManager.GetSecretValueResponse, AWS.AWSError>>
Returns a 'thenable' promise.
Coming in https://github.com/microsoft/TypeScript/pull/35998, hopefully
Most helpful comment
Just to clarify, for
Promisesto work correctly we need a more generalawaitedtype which unwrapsPromiseLikes recursively. If we had that, it would subsume thisPromiseResulttype.