更新后:mongoose模式中名为“model”的属性会引起麻烦

ssgvzors  于 9个月前  发布在  Go
关注(0)|答案(1)|浏览(159)

在更新我的Nest.js项目的包后,我的一些mongoose模式停止编译。抛出以下错误:
接口“LeasingValue”不正确地扩展了接口“Document<any,any,any Value”。属性“model”的类型不兼容。
类型“string”不可分配给类型“{ <ModelType = Model<unknown,{},Document<unknown,{},unknown> & Required<{ _id:unknown; }>,any>>(name:string):ModelType; <ModelType = Model<any,{},{},any,any>>():ModelType; }”
事实上,LeasingValue中有一个属性“model”,它是字符串类型的。这突然被禁止了,导致文档中名为“model”的mongoose属性出现问题。
我认为我监督的东西,应该有一个简单的修复比降级再次。在更新之前,它是可能有mongoose模式与一个属性称为“模型”。

uajslkp6

uajslkp61#

解决方案相当简单。不要使用Document作为扩展接口的类型来与mongoose模式一起使用,只需使用HydratedDocument类型。HydratedDocument表示当您调用

new Model(...)

字符串
实际结构如下所示:

export interface FirstTplImagePerModel extends HydratedDocument<any> {
    ...
    model: string
    ...
}


现在可以使用名为“model”的属性。

相关问题