用样式组件类型扩展HOC道具

时间:2020-10-22 12:44:09

标签: reactjs typescript styled-components

我正在尝试将样式化组件包装在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

0 个答案:

没有答案