Skip to content
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

Proposal: Promisable #40

Closed
fabiospampinato opened this issue May 29, 2019 · 4 comments · Fixed by #45
Closed

Proposal: Promisable #40

fabiospampinato opened this issue May 29, 2019 · 4 comments · Fixed by #45
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fabiospampinato
Copy link
Contributor

fabiospampinato commented May 29, 2019

Some times we are just awaiting a function, so we don't really care if the returned value is actually a promise or not. With Promisable:

type Promisable<T> = T | Promise<T>;

One could write this:

type Foo = () => Promisable<string | number | null>

Rather than:

type Foo = () => string | number | null | Promise<string> | Promise<number> | Promise<null>

It helps write a bit cleaner code. I'm not sure if it's useful enough to be included here, but I thought I'd mention it.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@kainiedziela
Copy link
Contributor

I'd be happy to integrate this.

@WORMSS
Copy link

WORMSS commented Jun 27, 2019

This could also be quite nice for Promise.all style arguments.

@sindresorhus
Copy link
Owner

Accepted on the condition that someone opens an issue on TypeScript requesting it be added as a built-in, and comments the link to the issue here. I think it's a very common need.

For anyone that wants to tackle this, please read guide for adding a type and also see how the last type was added: 22c3a99 (Note the extensive docs and comments).

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Jul 2, 2019
@fabiospampinato
Copy link
Contributor Author

fabiospampinato commented Jul 2, 2019

Accepted on the condition that someone opens an issue on TypeScript requesting it be added as a built-in, and comments the link to the issue here. I think it's a very common need.

👍 microsoft/TypeScript#32220


Edit: there was already an issue about this: microsoft/TypeScript#31394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants