小编Aka*_*rma的帖子

如果 Nest.js 中不能使用“any”,那么 schema 中的字段类型应该是什么?

我正在使用 Mongoose 在 Nest.js 中工作。创建模式时,我有一个字段 extra_options 可以存储任何类型的值(数组、对象、字符串等)。将其类型保持为“any”是行不通的。正确的类型应该是什么?这是代码片段。

@Schema({
    collection: 'xyz',
    timestamps: {
        updatedAt: 'updated_at',
        createdAt: 'created_at'
    },
})
export class xyz {
    @Prop({default: true})
    active: boolean;

    @Prop()
    extra_options: any;

    @Prop({required: true})
    created_by: string;
}
Run Code Online (Sandbox Code Playgroud)

javascript types mongoose typescript mongoose-schema

4
推荐指数
1
解决办法
5340
查看次数