Skip to content

Thoughts about variadic generics? #1773

Closed

Description

We can kind of already do this for functions by defining several overloads, but there is no corresponding mechanism for overloaded classes or interfaces. A typical use case would be defining a registry for callbacks which accept a number of parameters. Something like the following with loosely proposed variadic type syntax:

interface IDispatcher<...ArgTypes> {

  add(callback: (...args: ArgTypes) => void): void {
    // store the callback
  }

  dispatch(...args: ArgTypes): void {
    // invoke the callbacks
  }
}


function createDispatcher<...ArgTypes>(): IDispatcher<...ArgTypes> {
  // create a concrete instance
}


var d = createDispatcher<number, string>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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