I have a piece of code:
function reverse<T extends Number, D extends Number>(items: T[], m: D): T[] {
var toreturn = [];
for (var i = items.length - 1; i >= 0; i--) {
(()=>{
toreturn.push(items[i] * m);
})();
}
return toreturn;
}
var sample = [1, 2, 3];
var reversed = reverse(sample, 10);
console.log(reversed);
My IDE says that there are 2 error here:
Error:(5, 27) TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
Error:(5, 38) TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
It's basically about the entities cannot be multiplied because they are not numbers or other plausible type. I've added extends to the generic definition.
How can this be fixed?
Relevant typescript playground version is here