Closed
Description
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.
// 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) => (params2: T) => 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");
This is useful in e.g. typing the spread function here:
DefinitelyTyped/DefinitelyTyped@3eb67c9
I need to use the ...args: any[]
, which is not quite what I'm looking for.
In essence, the type I want to use is [A?, B?, C?, ...]
, or maybe something like Params<T>
if such an interface would exist.