Passing array as arguments in TypeScript

arguments, arrays, typescript

Solution

Use Function.prototype.apply:

T.m1.apply(this, args);

Where T is the enclosing class of `m1`.

Problem

I have two methods: ``` static m1(...args: any[]) { //using args as array ... } static m2(str: string, ...args: any[]){ //do something //.... //call to m1 m1(args); } ``` The call to `m1(1,2,3)` works as expect. However, the call `m2("abc",1,2,3)` will pass to `m1([1,2,3])`, not as expect: `m1(1,2,3)`. So, how to pass `args` as arguments when make call to `m1` in `m2`?

Original source