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

165
Vistas
Define prop type as string or specific component

I am trying to figure something out, that just won't work. I have a component that accepts a type headline. The component needs to accept a string, or a specific component, but nothing else:

export interface Props {
  headline: string | Component
}

I have tried a combination of React.ElementType<typeof Component>, typeof Component, ComponentType<typeof Component>, none of it works, because it either just allows everything, or it allows nothing but the string at all. I have tried to pass the component as a function too, with headline={() => <Component />}, which eliminates all type errors but this won't render the passed component any longer.

This feels basic to me and I am not sure what the proper way to go about this would be. What is the right typing for this use case?

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