react-polymorphic-types icon indicating copy to clipboard operation
react-polymorphic-types copied to clipboard

How to use with styled components

Open danvim opened this issue 2 years ago • 0 comments

Not strictly an issue of this library but a question about integrating with styled-components.

I have the following piece of code and styled-components is unable to deduce h1 attributes of StyledHeading. With only as={} suggested when creating a StyledHeading tag and any other attributes being any. Upon checking the typing from my IDE, I see that StyledHeading has type StyledComponent<PolymorphicForwardRefExoticComponent<P, any>, ...>.

import styled from 'styled-components'

export const Heading: PolymorphicForwardRefExoticComponent<
  HeadingOwnProps,
  typeof HeadingDefaultElement
>(...) => {...}

const StyledHeading = styled(Heading).attrs({
  forwardedAs: 'h1' // or as: 'h1'
})``

danvim avatar Jul 15 '23 05:07 danvim