A
A
Alexey Yarkov2016-02-13 00:06:47
JavaScript
Alexey Yarkov, 2016-02-13 00:06:47

How to use arguments in TypeScript?

Decided to use TypeScript in the project. The first time I work with him and immediately stumbled upon such a problem.
We create a class:

class AnonimChat {

  constructor(private $, private tpl) {

  }

  console(...params: any[]) {
    console[params[0]](params.slice(1));
  }

}


var AChat = new AnonimChat(()=>1, ()=>1);
AChat.console("log", "first", "second", 1, []);

Everything seems to be OK, but after running the compilation result, an array ["first", "second", 1, []] is passed to console.log , otherwise it is not an array, but the arguments in order. I xs what to do (((Tell the fool, please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-02-13
@yarkov

Function.prototype.apply

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question