meteor/mongo.Mongo.Collection
似乎是一个接口(根据these type declarations),网络上的大多数sample code都显示了如何扩展该接口,然后为方法中的方法编写代码单独的块:
export interface List {
_id?: string;
name?: string;
incompleteCount?: number;
}
export interface CollectionLists extends Mongo.Collection<List> {
defaultName(): string;
}
export var Lists = <CollectionLists>(new Mongo.Collection<List>('lists'));
// Calculate a default name for a list in the form of 'List A'
Lists.defaultName = function(): string {
var nextLetter = 'A', nextName = 'List ' + nextLetter;
while (Lists.findOne({name: nextName})) {
// not going to be too smart here, can go past Z
nextLetter = String.fromCharCode(nextLetter.charCodeAt(0) + 1);
nextName = 'List ' + nextLetter;
}
return nextName;
};
有没有办法用类重写这个例子而不是这个接口,为所有添加的方法使用单独的代码块?