Skip to content

Add PromiseResult type to standard lib #28105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
ethanresnick opened this issue Oct 24, 2018 · 6 comments
Closed
4 tasks done

Add PromiseResult type to standard lib #28105

ethanresnick opened this issue Oct 24, 2018 · 6 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ethanresnick
Copy link
Contributor

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)
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 24, 2018

See #17077, and discussion at

Search also for awaited, await, promised, unpromise, and unpromisify on the issue tracker.

@DanielRosenwasser
Copy link
Member

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.

@ajafff
Copy link
Contributor

ajafff commented Oct 24, 2018

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

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Oct 25, 2018
@deser
Copy link

deser commented Dec 12, 2019

Any progress here? :)

@westonkjones
Copy link

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.

@fregante
Copy link

Coming in #35998, hopefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants