Mikro ORM:属性在 orm.em.create() 上具有任何类型;

问题描述

我已经创建了一个产品实体,并使用 ORM 生成假数据。但是, em.create 使用 any 作为实体属性的类型。此外,em.create 使所有属性都可选,包括我明确设置为需要的属性,带有 ! 标记(例如,Product.name)。我看不出我做错了什么。这是代码

产品实体:

@Entity()
export class Product {
  @PrimaryKey()
  _id!: ObjectId;

  @SerializedPrimaryKey()
  id!: string;

  @property()
  name!: string;

  @property()
  createdAt: Date = new Date();

  @Property({ onUpdate: () => new Date() })
  updatedAt: Date = new Date();

  @property()
  description!: string;

  @property()
  image!: string;

  @property()
  price!: number;

  @property()
  tags: string[] = [];

  @property()
  quantity: number = 0;
}

em.create() 的类型

The types by em.create

请告诉我我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)