I am learning how to use the rest parameter/spread operator in typescript. Now, I need to write a function that takes an array as a parameter and I want to use the rest operator. This is the function:
insert(elem: number, ...elems: number[]) The elem parameter is there because I need the array to have at least one element.
So, given an array like this:
const numArray = [1, 2, 3, 4] How can I pass the array to the function? I've tried the following but it gave me an error:
insert(...numArray) I understand the error, because numArray may have from 0 to N elements, and the function needs at least one element, but I don't know the best solution to it.
Is there any way to achieve this?
Note: The insert function is part of a library that I'm developing, so I need to make it as usable as can be, and not depending on how the user will make use of it
