如何 cast/convert 枚举到 angular 中的另一个枚举

how to cast/convert enum to another enum in angular

这是我的代码:

/**
 * Invoice Type
 */
export enum InvoiceType {
  Instore = 'Instore',
  Marketplace = 'Marketplace'
}
/**
 * Invoice Interface
 */
export interface Invoice {
  invoice_type: InvoiceType,
}
/**
 * OrderType Interface
 */
export enum OrderType {
  Instore = 'Instore',
  Marketplace = 'Marketplace'
}
/**
 * Order Interface
 */
export interface Order {
  order_type: OrderType,
}

下订单后,我需要为其创建发票。

const invoice: Invoice = {
  invoice_type: order.order_type
}

我无法将下订单 OrderType 分配给发票 Order 类型。

我可以convert/castorder.order_type发票类型吗?

由于两个枚举存储相同的信息,只需创建一个枚举并引用它两次即可。见下文:

export enum OrderLocationType {
Instore = 'Instore',
Marketplace = 'Marketplace'
}
export interface Invoice {
invoice_type: OrderLocationType,
}
export interface Order {
order_type: OrderLocationType,
}