I'm trying to add a method to the Array object in Typescript. I've already found other solutions on SO, but none of those work for me.
My code looks like:
interface Array {
average(): () => number;
}
Array.prototype.average = () => {
var sum: number = 0
for (var i = 0; i < this.length; i++)
sum += this[i]
if (this.length)
return sum / this.length
return 0
}
And I get the error: The property 'average' does not exist on value of type 'Array'