Need to allow to use generics for "this" type, like this: this<T>
class Collection<T> extends Array<T> {
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): this {
// this method will return this<T>, but I want to return this<U>
return new (this.constructor as any)(...super.map(callbackfn, thisArg));
}
}
example of usage:
new Collection(
new Model(1, "Mercedes"),
new Model(2, "BMW"),
new Model(3, "Ford")
)
.map(model => model.engine)
.forEach(engine => engine.serialNumber); // here compiler should see engine.serialNumber
Need to allow to use generics for "this" type, like this:
this<T>example of usage: