Skip to content

Generic meta types #3779

Closed
Closed
@d180cf

Description

@d180cf

As far as I know, in Flow there are so called "generic meta types" that can operate on other types:

type C = $Merge<{a: number}, {b: string}>; // C = { a: number, b: string }
type A = $Args<(a: number, b: string) => void>; // A = [number, string]

Such "type algebra" would be useful to construct function signatures and interfaces that are hard/impossible to construct with other techniques:

interface TaggedFunction<Callable extends (...args) => any> {
  type Args = $Args<Callable>;
  type RetV = $RetV<Callable>;

  (...args: ...Args): RetV;
  tag: number;
  bind<...T>(...args: ...T): TaggedFunction<(...args: $Concat<Args, ...T>) => RetV>;
}

Do you think this would be a useful addition to the type system?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions