Question about Typescript/JavaScript.
I made my own custom log()
function that allows me to toggle logging on and off. Currently, I am using a simple console.log()
. Here is the code:
log(message: any): void {
console.log(message)
}
Recently, I decided to pass multiple parameters since console.log
can handle any number of parameters like console.log(a, b, c)
.
Therefore, I switched to using rest parameters and modified my function as follows:
log(...message: any[]): void {
console.log(message)
}
It works well. However, when I use my log
function with multiple parameters, console.log
outputs an array instead of separate values as if I called it directly.
I understand this is because the message can be interpreted as a single array parameter.
But is there a way to pass an array to console.log
(or any similar function) and indicate that it should be treated as multiple parameters?
I would prefer not to define 10 optional parameters and pass them as is :)