TypeScript call function with Rest Parameters from another with Rest Parameters

typescript

In TypeScript it is possible to declare a function with "Rest Parameters":

function test1(p1: string, ...p2: string[]) {
    // Do something
}

Suppose that I declared another function that called test1:

function test2(p1: string, ...p2: string[]) {
    test1(p1, p2);  // Does not compile
}

The compiler produces this message:

Supplied parameters do not match any signature of call target:
Could not apply type 'string' to argument 2 which is of type 'string[]'.

How can test2 call test1 will the supplied arguments?

Best Answer

Try the Spread Operator. It should allow for the same effect as in Jeffery's answer but has a more concise syntax.

function test2(p1: string, ...p2: string[]) {
    test1(...arguments);
}