I want a component to accepts different props based on the value of a given, specific one. Something like the following.
const Button: React.FC<TButton> = ({ href, children, ...rest }) => {
if (href) {
return <a href={href} {...rest}>{children}</a>
}
return <button {...rest}>{children}</button>
}
type TButton = { href: string & IAnchor } | { href: undefined & IButton }
interface IAnchor extends React.AnchorHTMLAttributes<HTMLAnchorElement> {}
interface IButton extends React.ButtonHTMLAttributes<HTMLButtonElement> {}
Thing is, can't figure how to go through this properly. I mean, it seems the conditions aren't being parsed or interpreted correctly.
If you want to have a closer look at the issue, please refer to this StackBlitz.