Skip to content

Type for arbitrary number of function parameters of specified types #4338

Closed
@panuhorsmalahti

Description

@panuhorsmalahti

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions