如何使用Typescript扩展/实现Meteor中的Mongo.Collection?
看来,如何使用Typescript扩展/实现Meteor中的Mongo.Collection?,meteor,typescript,Meteor,Typescript,看来,meteor/mongo.mongo.Collection是一个接口(根据),web上的大多数示例演示了如何扩展该接口,然后在单独的块中为方法编写代码: export interface List { _id?: string; name?: string; incompleteCount?: number; } export interface CollectionLists extends Mongo.Collection<List>
meteor/mongo.mongo.Collection
是一个接口(根据),web上的大多数示例演示了如何扩展该接口,然后在单独的块中为方法编写代码:
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;
};
导出接口列表{
_id?:字符串;
名称?:字符串;
不完全计数?:数字;
}
导出接口CollectionList扩展了Mongo.Collection{
defaultName():字符串;
}
导出变量列表=(新的Mongo.Collection('list');
//以“列表a”的形式计算列表的默认名称
Lists.defaultName=函数():字符串{
变量nextLetter='A',nextName='List'+nextLetter;
while(Lists.findOne({name:nextName})){
//在这里不太聪明,可以通过Z
nextLetter=String.fromCharCode(nextLetter.charCodeAt(0)+1);
nextName='List'+nextLetter;
}
返回下一个名称;
};
有没有办法用类来重写这个例子,而不是用单独的代码块来重写这个接口