打字稿:错误 TS2314:通用类型 'Array<T>' 需要 1 个类型参数

Shi*_*pta 2 typescript

我正在学习打字稿,并且编写了非常基本的代码。

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 个类型参数我哪里做错了?

Osc*_*Paz 5

通用数组必须定义为:

  • const arr = new Array<string>()
  • const arr = string[]