How can I add a method to a typed array like Array<MyClass>?
Consider a case where you have a typed array where it might make sense to offer a property/method to calculate a value by accessing all items of the array.
class Foo {
date: Date
}
class FooArray extends Array<Foo> {
dateInterval() {
// Some algorithm that iterates over all dates to find
// min/max
return this.reduce(..)
}
}
But something tells me that I'm going the wrong way. For example, FooArray.splice() returns the type Foo[], not FooArray, which makes total sense to me.
Can anyone point me into the right direction?