const range = (...myData: number[]) => {
myData.sort();
return myData[myData.length-1] - myData[0];
}
Codecademy explains that even though the rest parameter type is an array of numbers, it's acceptable to call range() without any arguments and no TypeScript error will be generated. However, this results in a NaN value being returned.
I was under the impression that TypeScript would throw an error if we fail to provide values for a function's arguments, unless they are marked with a ?
after their name.