Here is my component:
import {Button, Tabs} from 'antd';
import * as React from "react";
import {ReactElement} from "react";
import {IBaseComponentProps} from "../BaseComponent/BaseComponent";
const operations = <Button type={"primary"}>Extra Action</Button>;
export interface ITabContent {
title: string,
content: ReactElement<any>
}
interface ITabProps extends IBaseComponentProps {
tabs: ITabContent[]
}
export const Tab: React.SFC<ITabProps> = props => {
const tabs: any = [];
props.tabs.forEach((tab: ITabContent, index: number) => {
tabs.push(<Tabs.TabPane tab={tab.title} key={index}>{tab.content} </Tabs.TabPane>)
});
return (
<Tabs tabBarExtraContent={operations}>
{...tabs}
</Tabs>
);
};
I want to force tabs in my props to not be empty, preferably I would like a compile time error.
I know you can do something like a "OR" with type inference in typescript:
boolean = "false" | "true"
But I can't seem to figure out a way to type tabs correctly. For example, I tried something like :
tabs: ITabContent[] & !never[]
But this obviously doesn't compile. Is there an equivalent operator to "&" that I am not aware of?
tabs: ITabContent[]it will only allow array with those properties