【发布时间】:2016-05-24 20:49:21
【问题描述】:
我在 nodejs 中编写打字稿。当我编写猫鼬模式时,Typescript 编译器告诉我如下:
app/models/user.schema.ts(15,12): error TS2339: Property 'methods' does not exis
t on type 'Schema'.
我觉得很奇怪。我在guide 的Instance methods 部分参考了文档。它提到如下:
// assign a function to the "methods" object of our animalSchema
animalSchema.methods.findSimilarTypes = function (cb) {
return this.model('Animal').find({ type: this.type }, cb);
}
我认为methods 是一个可用的属性或API。但是对于打字稿,这是错误的。
接下来,我查找定义。我找到了method(name: string, fn: Function) 和method(method: Object) 这些属性,但它没有methods。
简而言之,你不回答我为什么猫鼬定义的作者没有定义属性。我需要一个答案 mongoose 中的 methods 实际上是否可用?
【问题讨论】:
标签: javascript node.js mongoose typescript definition