I am trying to add a method which would belong to a class extending Arrays of device with Typescript (3.7.5).
export class devices extends Array<device> {
constructor(items?:Array<device>) {
super(...items);
}
getDeviceByUid(uid: number): device {
return this.filter(elmt => elmt.uid == uid)[0];
}
}
But I also need to be able to declare and define an empty array, like I would do with a normal array:
unfilteredDeviceList: devices = []; //error : Property 'getDeviceByUid' is missing in type 'undefined[]' but required in type 'devices'.
So I tried like so:
unfilteredDeviceList: devices = new devices();
I get no compile time errors when doing the latest, but in runtime : Error: Uncaught (in promise): TypeError: super is not iterable (cannot read property Symbol(Symbol.iterator))
What is the way to declare and define an extended empty array, or what should I change in the constructor?