0

我创建了一个产品实体,并使用 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() 的类型

em.create 的类型

请让我知道我做错了什么?

4

0 回答 0