Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda