请问如何对数组类型type提出一条元素 & 其他的type,进而做一个props?
我现在有如下的props
export type TabsCompProps = {
label: string,
children: React.ReactNode,
key: string,
breadcrumbs: string[]
}[]
export type DetailProps = {
content: string
}
我想要做一个props如下:
type TabsWithDetailProps = {...}[]
TabsWithDetailProps是一个数组,数组里面的元素由TabsCompProps数组提出的一条信息和DetailProps 组成。请问应该如何做呢?
回复
1个回答
test
2024-06-27
type TabsCompProps = {
label: string;
children: React.ReactNode;
key: string;
breadcrumbs: string[];
}[];
type DetailProps = {
content: string;
};
type TabsWithDetailProps = (TabsCompProps[number] & DetailProps)[];
// 示例
const tabsWithDetail: TabsWithDetailProps = [
{
label: "Tab 1",
children: <div>Content 1</div>,
key: "1",
breadcrumbs: ["Home", "Tab 1"],
content: "Detail Content 1",
},
{
label: "Tab 2",
children: <div>Content 2</div>,
key: "2",
breadcrumbs: ["Home", "Tab 2"],
content: "Detail Content 2",
},
];
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容