Passing array as arguments in TypeScript Passing array as arguments in TypeScript arrays arrays

Passing array as arguments in TypeScript


Actually, using the ... again when calling the method will work.

It generates the apply call for you in javascript.

static m1(...args: any[]) {    //using args as array ...}static m2(str: string, ...args: any[]){    //do something    //....    //call to m1    // m1(args);    // BECOMES    m1(...args);}


Use Function.prototype.apply:

T.m1.apply(this, args);

Where T is the enclosing class of m1.