Recently, I decided to experiment a bit with TypeScript. I ended up creating two classes - Student and Listview. The goal was to loop over an array of student objects that I had created but for some reason, it's not working as expected.
class Student {
fullName: string;
constructor(public firstName, public middleInitial, public lastName) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
class Listview {
items: Array<Student>;
constructor(public item_list: Array<Student>) {}
log(): void {
var items = this.items;
for(var i=0; i<items.length; i++) {
console.log(items[i]);
}
}
}
var list = new Listview(
[new Student("Jane", "M.", "User"),
new Student("Hans", "M.", "Muster"),
new Student("Fritz", "B.", "Muster")]
);
list.log();
Upon checking the console, I noticed a warning message:
I'm struggling to understand how to properly access the array in order to retrieve the properties of each student object. Any help or advice would be greatly appreciated.
Best regards, Orkun