I would like to make a new class that derives from Array that has its own methods in addition to the regular array methods.
export class ObjectCollection<T extends Iidentifier> extends Array<T> {
constructor(collection: T[] = []) {
super(...collection);
}
// used for getting instance from a collection of objects
public getInstance(id: Id) {
return this.find(item => item.Id.toString() === id.toString()) || new
Array<T>();
}
}
I have also have child classes that inherit from that class.
export class TargetCategories extends ObjectCollection<TargetCategory> {
constructor(categories: TargetCategory[] = []) {
super(categories);
}
public getCategoryType(id: Iidentifier): string {
return this[id].Category.length < 2 ? "dummy" : "saved";
}
}
When I instantiate a TargetCategories object, I'm only able to use methods that are in array though. I'm not able to call things like getCategoryType and getInstance.