<p dir="auto">I'd like to have a type for a function which takes in zero or more parameters, and then use the type for the parameters, e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// Note: the syntax below of course doesn't do what I'm looking for, something like (params: ...args: T) would be closer
let f = (params: T) =&gt; (params2: T) =&gt; 0;

// these should be legal:
f(5)(3);
f(&quot;foo&quot;)(&quot;bar&quot;);
f(5, &quot;foo&quot;)(3, &quot;bar&quot;);

// these should be illegal
f(5)(&quot;bar&quot;);
f(&quot;foo&quot;)(3);
f(5, 3)(&quot;foo&quot;, &quot;bar&quot;);"><pre class="notranslate"><code class="notranslate">// Note: the syntax below of course doesn't do what I'm looking for, something like (params: ...args: T) would be closer
let f = (params: T) =&gt; (params2: T) =&gt; 0;

// these should be legal:
f(5)(3);
f("foo")("bar");
f(5, "foo")(3, "bar");

// these should be illegal
f(5)("bar");
f("foo")(3);
f(5, 3)("foo", "bar");
</code></pre></div>
<p dir="auto">This is useful in e.g. typing the spread function here:<br>
<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/DefinitelyTyped/DefinitelyTyped/commit/3eb67c9e8258d2894f728016a427b963a94f22ce/hovercard" href="https://github.com/DefinitelyTyped/DefinitelyTyped/commit/3eb67c9e8258d2894f728016a427b963a94f22ce">DefinitelyTyped/DefinitelyTyped@<tt>3eb67c9</tt></a></p>
<p dir="auto">I need to use the <code class="notranslate">...args: any[]</code>, which is not quite what I'm looking for.</p>
<p dir="auto">In essence, the type I want to use is <code class="notranslate">[A?, B?, C?, ...]</code>, or maybe something like <code class="notranslate">Params&lt;T&gt;</code> if such an interface would exist.</p>
<p dir="auto">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:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface IDispatcher&lt;...ArgTypes&gt; {

  add(callback: (...args: ArgTypes) =&gt; void): void {
    // store the callback
  }

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


function createDispatcher&lt;...ArgTypes&gt;(): IDispatcher&lt;...ArgTypes&gt; {
  // create a concrete instance
}


var d = createDispatcher&lt;number, string&gt;();"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">IDispatcher</span><span class="pl-c1">&lt;</span>...<span class="pl-smi">ArgTypes</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>

  <span class="pl-c1">add</span><span class="pl-kos">(</span><span class="pl-s1">callback</span>: <span class="pl-kos">(</span>...<span class="pl-s1">args</span>: <span class="pl-smi">ArgTypes</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">)</span>: <span class="pl-smi"><span class="pl-k">void</span></span> <span class="pl-kos">{</span>
    <span class="pl-c">// store the callback</span>
  <span class="pl-kos">}</span>

  <span class="pl-en">dispatch</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span>: <span class="pl-smi">ArgTypes</span><span class="pl-kos">)</span>: <span class="pl-k">void</span> <span class="pl-kos">{</span>
    <span class="pl-c">// invoke the callbacks</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>


<span class="pl-k">function</span> <span class="pl-en">createDispatcher</span><span class="pl-c1">&lt;</span>...<span class="pl-smi">ArgTypes</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">IDispatcher</span><span class="pl-kos">&lt;</span>...<span class="pl-smi">ArgTypes</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-c">// create a concrete instance</span>
<span class="pl-kos">}</span>


<span class="pl-k">var</span> <span class="pl-s1">d</span> <span class="pl-c1">=</span> <span class="pl-en">createDispatcher</span><span class="pl-kos">&lt;</span><span class="pl-smi">number</span><span class="pl-kos">,</span> <span class="pl-smi">string</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>