Skip to content

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

Description

@bcherny

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.

Activity

  1. mhegazy commented on Nov 29, 2017

    @mhegazy
    Contributor

    I think the example should be

    type F = {
        (): number;
        (): string;
    }
  2. bcherny commented on Nov 29, 2017

    @bcherny
    Author

    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.

  3. bcherny commented on Mar 4, 2018

    @bcherny
    Author

    This is now done with ReturnType in #21847.

  4. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions