Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Typescript扩展/实现Meteor中的Mongo.Collection?_Meteor_Typescript - Fatal编程技术网

如何使用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;
}
返回下一个名称;
};
有没有办法用类来重写这个例子,而不是用单独的代码块来重写这个接口