Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda