I recently started my journey in learning typescript and have written some basic code.
class Learning {
subjects: Array[string];
hoursPerDay: number;
constructor(subj: Array[string], hrs: number) {
this.subjects = subj;
this.hoursPerDay = hrs;
}
displaySubjects():void{
for(let i=0; i<this.subjects.length; i++){
console.log(this.subjects[i]);
}
}
}
let topics=["Math", "Science", "History"];
let learning = new Learning(topics, 5);
learning.displaySubjects();
I am encountering an error whenever I use an array:
Error TS2314: Generic type 'Array' requires 1 type argument(s). What am I doing wrong?