我在nodejs中編寫打字稿。當我編碼貓鼬模式時,Typescript編譯器如下所示:Typescript - 爲什麼'方法'屬性不存在於貓鼬中?
app/models/user.schema.ts(15,12): error TS2339: Property 'methods' does not exis
t on type 'Schema'.
我覺得很奇怪。我已經在guide的Instance methods
部分提及doc。它提到如下:
// 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
。
總之,你不回答我爲什麼貓鼬定義的作者沒有定義屬性。我需要一個答案methods
mongoose
實際上是否可用?