Issue
I want to create and interface for a component props. Currently it looks like this:
interface IContextMenuProps {
text: string;
image: string;
}
I want the text to be optional if image is provided and viceversa. On other words, one of them has to exist.
Solution
In your case you need to use union.
Type will be something like this:
type IContextMenuProps = ({ text: string } | { image: string });
Answered By - xom9ikk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.