I have a function that accepts a rest parameter.
function getByIds(...ids: string){
...
}
I know I can call getByIds('andrew')
and getByIds('andrew','jackson')
and it will convert the strings into an array of strings.
My question is: can I call getByIds(['andrew','jackson'])
, if I already have the parameters merged into an array?
In Java I know I could, but typescript seems to give me problems. JsFiddle fails me too.
Yeah, you can use the spread operator:
getByIds(...['andrew', 'jackson']);
It compiles to:
getByIds.apply(void 0, ['andrew', 'jackson']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With