我正在学习打字稿,并且编写了非常基本的代码。
class School {
nameOfStudents: Array[string];
noOfteachers: number
constructor(name: Array[string], no: number) {
this.nameOfStudents = name;
this.noOfteachers = no;
}
printName():void{
for(let i=0;i<this.nameOfStudents.length;i++){
console.log(this.nameOfStudents[i])
}
}
}
let arr=["a","b","c","d","e"]
let school = new School(arr,100);
school.printName();Run Code Online (Sandbox Code Playgroud)
在我使用数组的地方,我收到以下错误:
错误 TS2314:通用类型“数组”需要 1 个类型参数我哪里做错了?
| 归档时间: |
|
| 查看次数: |
9056 次 |
| 最近记录: |