bạn có thể thử gói này https://www.npmjs.com/package/mongoose- ts-ua
@setSchema()
class User1 extends User {
@prop()
name?: string;
@setMethod
method1() {
console.log('method1, user1');
}
}
@setSchema()
class User2 extends User {
@prop({ required: true })
name?: string;
@prop()
child: User1;
}
export const User2Model = getModelForClass<User2, typeof User2>(User2);
sử dụng
let u2 = new User2Model({ child: { name: 'u1' } });