[英]How to properly type mongoose referenced document in typescript
The mongoose.Types.ObjectId works fine but I want to better type it using the User Document type, so if I populate it, it will infer the correct type like profile.user.toObject({getters:true})
. mongoose.Types.ObjectId 工作正常,但我想使用 User Document 类型更好地输入它,所以如果我填充它,它会推断出正确的类型,如profile.user.toObject({getters:true})
。 I saw articles using UserDocument['id']
but it will return any
.我看到了使用UserDocument['id']
但它会返回any
. is there a proper way to type this?有没有正确的方法来输入这个?
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.