What could be the issue with my code below?
I've attempted to extend the Array
object in my class called MyNumberList
. However, when I try to add items to the list, nothing seems to be happening. When I try to access the elements in the list, I only get undefined
.
By the way, I'm using TypeScript version 1.8.2.
class MyNumberList extends Array<number> {
constructor(...numbers: number[]) {
// It seems like this part is not functioning as expected
super(...numbers);
}
}
let numbersList: MyNumberList = new MyNumberList(10, 20, 30);
console.log(numbersList[0]); // Outputs undefined
console.log(numbersList.length); // Outputs 0
>