You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type for arbitrary number of function parameters of specified types #4338
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");
Looks like you want something that allows a variable number of parameters with arbitrary types, but then captures them so they can be repeated in another signature. I think you may find a relevant discussion at #3622 (comment) and #3870.
Activity
JsonFreeman commentedon Aug 24, 2015
Looks like you want something that allows a variable number of parameters with arbitrary types, but then captures them so they can be repeated in another signature. I think you may find a relevant discussion at #3622 (comment) and #3870.
benliddicott commentedon Sep 7, 2015
Do you actually need an infinite number of parameters? If in practice you top out at something like ten or twenty then this might be a good pattern:
It's flexible, doesn't require new syntax, and works today.
JsonFreeman commentedon Sep 8, 2015
That is indeed the recommended pattern to use today.
mhegazy commentedon Feb 22, 2016
looks like a duplicate of #1773