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

Get union of all possible return types of a function #20350

Closed
bcherny opened this issue Nov 29, 2017 · 3 comments
Closed

Get union of all possible return types of a function #20350

bcherny opened this issue Nov 29, 2017 · 3 comments
Labels
Suggestion An idea for TypeScript

Comments

@bcherny
Copy link

bcherny commented Nov 29, 2017

For example:

type F = () => number | string
type G = returnof F // number | string

If there is interest, I will write up a proposal.

Note that this is distinct from #6606, which gives a return type given parameter types.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 29, 2017

I think the example should be

type F = {
    (): number;
    (): string;
}

@bcherny
Copy link
Author

bcherny commented Nov 29, 2017

You're right - your example shows more clearly that we're taking the union of all return types. In this example, returnof both my F and yours should give number | string.

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Nov 30, 2017
@bcherny
Copy link
Author

bcherny commented Mar 4, 2018

This is now done with ReturnType in #21847.

@bcherny bcherny closed this as completed Mar 4, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants