Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
How to type a styled component so that I can pass {...rest} as prop without getting no overload matches this call TypeScript error?

I have a component that returns a styled component to which it passes a variant prop. I also want to spread the rest of the props using {...rest} , however as soon as I do that, I get a typescript error because my styled component is not expecting any other props. How am I supposed to indicate that the styled component can expect spread props?

type HeaderVariant = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';

type Props = {
    variant?: HeaderVariant;
    style?: StyleProp<ViewStyle>;
} & TextProps;
interface StyledBaseButtonProps {
    variant: HeaderVariant;
}

const HeaderText: FunctionComponent<Props> = ({ variant = 'h1', children, ...rest }) => {
    return (
        <StyledText variant={variant} {...rest}>
            {children}
        </StyledText>
    );
};

const StyledText = styled.Text<StyledBaseButtonProps>`
    font-family: ${(props) => styles[props.variant].fontFamily};
    color: ${(props) => styles[props.variant].color};
    font-weight: ${(props) => styles[props.variant].fontWeight};
    font-size: ${(props) => styles[props.variant].fontSize};
    line-height: ${(props) => styles[props.variant].lineHeight};
`;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!