Is it possible to create an interface with multiple properties where one is required if the other is used?
For example:
interface MyProps {
onPressAll: () => void;
icon?: ImageSourcePropType;
onPressIcon?: () => void;
}
What I'm looking for is this: if icon is set, then onPressIcon must be present (or vice versa), otherwise neither should be used.
For instance, when calling my component:
<MyComponent
onPressAll={() => {}}
icon={myIcon}
/>
// An error should be returned because onPressIcon is missing
<MyComponent
onPressAll={() => {}}
onPressIcon={() => {}}
/>
// An error should be returned because icon is missing
<MyComponent
onPressAll={() => {}}
/>
// OK
<MyComponent
onPressAll={() => {}}
onPressIcon={() => {}}
icon={myIcon}
/>
// OK
Thank you!