Answer the question
In order to leave comments, you need to log in
Conditions when creating interface\type typescript?
How to specify that if there is no icon, then there must be text and vice versa?
type IProps = {
data: { icon?: React.ReactSVGElement; text?:string; id:string | number}[];
handleClick: (id: string | number) => void;
};
Answer the question
In order to leave comments, you need to log in
type IProps = {
data: (({ icon: any; } | { text: string; }) & { id: string | number })[];
};
type IProps = {
data: Data[];
};
type Data = Data.WithIcon | Data.WithText;
namespace Data {
interface Base {
id: string | number;
}
export interface WithIcon extends Base {
icon: any;
}
export interface WithText extends Base {
text: string;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question