答案 0 :(得分:2)
您是否只能将属性定义为联合类型并使用typeguard? 像这样:
type ButtonProps = { onClick: () => {} }
type LinkProps = { href: string }
type BaseProps = {
spinner?: boolean
}
type Props = BaseProps & (ButtonProps | LinkProps)
export const Button = (props: Props) => {
if ('href' in props) {
// Link
} else {
// Button
}
}