I have created a function which takes a component and returns a Styled component of that
import styled from 'styled-components';
const withStyled = (Component, styles) => {
const StyledComponent = styled(Component)`
${styles}
`;
return StyledComponent;
};
export default withStyled;
I am using this withStyled function as below
import cx from 'classnames';
import React from 'react';
import withStyled from '../../../hoc/withStyled';
import styles from './Paragraph.style';
interface Props {
className: string;
sizeVariant: string;
children: string;
}
const Paragraph = (props: Props) => {
const { children, className, ...extraProps } = props;
return (
<p className={cx('paragraph', className)} {...extraProps}>
{children}
</p>
);
};
const StyledParagraph = withStyled(Paragraph, styles);
export default StyledParagraph;
But when I am using my Paragraph component, VS code intellisense is not showing me suggestions related to props This is because withStyled function is returning me a new component and my original component's types are lost in the process.
Is there a way to get the original types in StyledComponent too?