我有以下界面:
export interface ProductInterface {
id: number;
ean: string;
title: string;
brand: string;
shortdescription: string;
fulldescription: string;
image: string;
weight: string;
price: string;
category: string;
subcategory: string;
subsubcategory: string;
}
我想创建一个扩展属性的类型
x.products.product.map((prod: Data) => ({
id: prod._attributes.Id,
ean: prod.ean._text,
title: prod.title._text,
brand: prod.brand._text,
type Data = ProductInterface & {
_attributes: { Id: number };
this: { _text: string };
};
这可能吗?
答案 0 :(得分:0)
我解决了问题
interface ProductAttributes {
_attributes: { Id: number };
}
type ProductText = { [P in keyof ProductInterface]: { _text: string } };
type ProductApiData = ProductAttributes & ProductText;