这是我的代码:
/**
* 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
类型。
我可以将 order.order_type
转换/转换为发票类型吗?
答案 0 :(得分:0)
由于两个枚举存储相同的信息,只需创建一个枚举并引用它两次。见下文:
export enum OrderLocationType {
Instore = 'Instore',
Marketplace = 'Marketplace'
}
export interface Invoice {
invoice_type: OrderLocationType,
}
export interface Order {
order_type: OrderLocationType,
}