-
-
Notifications
You must be signed in to change notification settings - Fork 545
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: AsyncReturnType #49
Comments
What's the practical difference to #42 (apart from the fact that |
@dylang ⬆️ |
I think that's difference. It's just a combination of them: Unpromise<ReturnType<typeof asyncFunction>>
ResolvedType<typeof asyncFunction> Funny thing is that all the examples in #38 and #42 are exactly: Unpromise<ReturnType<typeof asyncFunction>> So perhaps Also maybe it should be called |
This is what I'm using currently: type Unpromise<MaybePromise> = MaybePromise extends Promise<infer Type> ? Type : MaybePromise;
type AsyncReturnType<T extends (...args: any) => any> = Unpromise<ReturnType<T>> You can probably merge the two and avoid |
I still think PR welcome for |
Relevant TypeScript issue: microsoft/TypeScript#28105 |
@sindresorhus I think that's more about A PR for that issue has been opened: microsoft/TypeScript#35998 |
@sindresorhus Since you're accepting PRs for this, do you want me to submit one for this after |
@resynth1943 Yes. That would be great. 🙌 |
Gotcha. When you get a chance, @sindresorhus, could you check out #75? |
Reason
TypeScript provides ReturnType to infer what type a function returns, but it isn't as as useful when functions return a promise and you want to know what type the promise resolves to.
Proposal
ResolvedType
which returns the type of a function that returns a promise, but also works if the function is not a promise.Example
Proof of concept
Not tested extensively, may have bugs!
Existing work
I haven't seen anything like this before, but that doesn't mean it doesn't exist. I'm not fluent with other typed languages to know if there's a reason this doesn't exist or better way to implement it.
The text was updated successfully, but these errors were encountered: