[英]How to properly type mongoose referenced document in typescript
mongoose.Types.ObjectId 工作正常,但我想使用 User Document 類型更好地輸入它,所以如果我填充它,它會推斷出正確的類型,如profile.user.toObject({getters:true})
。 我看到了使用UserDocument['id']
但它會返回any
. 有沒有正確的方法來輸入這個?
interface IProfile {
user: // <- what type to put here (reference to User model)
bio: string
jobTitle: string
}
根據文檔,它應該通過使用PopulatedDoc
來工作,但在你的情況下,我得到any
作為結果類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.