请问如何对数组类型type提出一条元素 & 其他的type,进而做一个props?-灵析社区

winkkkkk9421

我现在有如下的props export type TabsCompProps = { label: string, children: React.ReactNode, key: string, breadcrumbs: string[] }[] export type DetailProps = { content: string } 我想要做一个props如下: type TabsWithDetailProps = {...}[] TabsWithDetailProps是一个数组,数组里面的元素由TabsCompProps数组提出的一条信息和DetailProps 组成。请问应该如何做呢?

阅读量:269

点赞量:11

问AI
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: Content 1, key: "1", breadcrumbs: ["Home", "Tab 1"], content: "Detail Content 1", }, { label: "Tab 2", children: Content 2, key: "2", breadcrumbs: ["Home", "Tab 2"], content: "Detail Content 2", }, ];