我正在尝试将样式化组件包装在HOC中,并扩展基本的prop类型。我希望下面的示例能正常工作,但出现TS错误Property 'active' does not exist on type...
interface CustomCardProps {
active: boolean
}
export const CustomCard: React.FC<CardItem & typeof CustomCardStyle> = ({
active,
children,
...other
}) => (
<CustomCardStyle active={active} {...other}>
{active ? children : null}
</CustomCardStyle>
)
const CustomCardStyle = styled(Card)<CustomCardProps>``
能够直接扩展样式化组件的类型将使我免于导入基础道具,并将包括实际样式化组件中缺少的类型,例如as
。
export const CustomCard: React.FC<CardItem & CardProps & CustomCardProps>
相似的问题:Styled component in HOC