Skip to content

Feature Request: a rest parameter of type "Array of Tuples" should expand to a repeating parameter list of the Tuple's type #56776

Closed

Description

🔍 Search Terms

Tuple, varargs, rest parameter, rest argument, function signature, variadic tuple types, spread syntax

✅ Viability Checklist

⭐ Suggestion

Here is a playground demonstrating the functionality I expected from the function signatures:

declare const tupleRestParams: (
  input: string,
  ...translations: [string, string]
)=> string;

tupleRestParams("input", "a"); // errors as expected
tupleRestParams("input", "a", "b"); // compiles as expected
tupleRestParams("input", "a", "b", "c"); // errors as expected
tupleRestParams("input", "a", "b", "c", "d"); // errors as expected
tupleRestParams("input", "a", "b", "c", "d", "e", "f"); // errors as expected

declare const tupleArrayRestParams: (
  input: string,
  ...translations: [string, string][]
)=> string;

tupleArrayRestParams("input", "a"); // errors as expected
tupleArrayRestParams("input", "a", "b"); // unexpected error! expected this to compile
tupleArrayRestParams("input", "a", "b", "c"); // errors as expected
tupleArrayRestParams("input", "a", "b", "c", "d"); // unexpected error! expected this to compile
tupleArrayRestParams("input", "a", "b", "c", "d", "e"); // errors as expected
tupleArrayRestParams("input", "a", "b", "c", "d", "e", "f"); // unexpected error! expected this to compile

declare const multiTypeTupleArrayRestParams: (
  input: string,
  ...translations: ([string, number])[]
)=> string;

multiTypeTupleArrayRestParams("input", "a"); // errors as expected
multiTypeTupleArrayRestParams("input", "a", 1); // unexpected error! expected this to compile
multiTypeTupleArrayRestParams("input", "a", 1, "c"); // errors as expected
multiTypeTupleArrayRestParams("input", "a", 1, "c", 2); // unexpected error! expected this to compile
multiTypeTupleArrayRestParams("input", "a", 1, "c", 2, "e"); // errors as expected
multiTypeTupleArrayRestParams("input", "a", 1, "c", 2, "e", 3); // unexpected error! expected this to compile

📃 Motivating Example

I consider myself a newbie, but given the syntax of the above example, my expected behavior feels more intuitive than the actual behavior. In dynamically typed languages like JavaScript, a repeating sequence of types doesn't seem too unusual. At least, it's common throughout the Clojure API.

However, "a function with a repeating set of parameters" requires using some advanced types to pull off, AFAIK.

💻 Use Cases

  1. What do you want to use this for? This is come up more than once while writing typescript, and not just for libraries. For example, I wanted to recreate linux's tr command with a signature like this:
    const tr = (
      input: string,
      ...translations: [string, string][]
    ): string => {
        return ""
    };
    
    I believe that signature means something different from my intention, therefore some additional syntax may be required.
  2. What shortcomings exist with current approaches? Additional syntax may be required. It may already be possible to do this and I just don't know the syntax.
  3. What workarounds are you using in the meantime? This can be achieved with recursive conditional types.

Activity

  1. jcalz commented on Dec 14, 2023

    @jcalz
    Contributor

    The thing you're trying to express is a duplicate of #40229

  2. DanKaplanSES commented on Dec 14, 2023

    @DanKaplanSES
    Author

    The thing you're trying to express is a duplicate of #40229

    Thanks, I figured it would've been mentioned already but I didn't find it when I searched.

    Is this a complete overlap? I wonder because the examples in #40229 all repeat the same type (string), whereas I'm requesting a way of repeating sequences of heterogeneous types. In addition, I'm not clear about how #40229 would work syntactically if worked as described as a function rest parameter.

    I'm assuming the answer is "yes, it completely overlaps," but I figured I'd ask because I might learn something by doing so :)

  3. jcalz commented on Dec 14, 2023

    @jcalz
    Contributor

    The types in the example in the other isssue are heterogeneous too; they’re string literal types.

  4. DanKaplanSES commented on Dec 14, 2023

    @DanKaplanSES
    Author

    The types in the example in the other isssue are heterogeneous too; they’re string literal types.

    Oh yeah, I didn't notice that. Thanks again.

  5. locked as resolved and limited conversation to collaborators on Oct 22, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions