So I'm trying to write a prop type format wherein if one was chosen the other prop will be discarded.
type ButtonProps = {
to: string,
} | {
onClick: (() => void)
};
export const BackButton = (props: ButtonProps) => {
if(props.to != null) {
//props {to} will be used hence no need for onClick
}
else {
// {onClick} will be used over {to}
}
}
But it says
Property 'to' does not exist on type 'ButtonProps'. Property 'to' does not exist on type '{ onClick: () => void; }'.ts(2339`
How to format type shape with OR so when either one is chosen the other will be discarded. No optionals, the chosen prop will be required.