Typescript 使用Backbone.js中的Collection.model属性

Typescript 使用Backbone.js中的Collection.model属性,typescript,Typescript,我有以下代码: class Student extends Backbone.Model { // id, lastname, firstname, birthdate } class StudentList extends Backbone.Collection { model = Student; ... } 我总是遇到这样的错误 Type of overridden member 'm

我有以下代码:

    class Student extends Backbone.Model { 
        // id, lastname, firstname, birthdate 
    }


    class StudentList extends Backbone.Collection { 
        model = Student;  
        ... 
    }
我总是遇到这样的错误

    Type of overridden member 'model' is not subtype of original member defined by type 'Collection'    ...
在一个官方示例中,代码几乎相同。它在那里工作(Todo->TodoList)。我的主骨d.ts中的收藏声明如下

...
model:Model;
...

有什么想法吗?

您正在使用
model=Student将var
model
的值设置为
Student
类型


要覆盖变量,您需要
model:Student并设置需要的值
model:Student=nameofSomeInstanceOffClassStudent(或者只是
model=nameOfSomeInstanceOfClassStudent;
)或者,如果您正在用一个新学生初始化它,
model:student=new student()

我通过在构造函数中指定模型类型解决了这个问题

 export class Users extends Backbone.Collection<Models.User> {
     constructor(models?: Models.User[], options?: any) {
      super(models, options);

      this.model = Models.User;
     }
    }
导出类用户扩展主干。集合{
构造函数(模型?:模型。用户[],选项?:任何){
超级(型号、选项);
this.model=Models.User;
}
}