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

371
Visualizações
How to fix: type '{ source: string; }' is not assignable to type 'string'

This has to be a simple fix, but I can't find anything explaining how you resolve this issue. I'm using Next.js and Typescript to make a component display an image and use hooks to modify said image. The problem is, when I pass in a string to the parameter that is typed as string, I get this error: Type '{ source: string; }' is not assignable to type 'string'.ts(2322)

Given this component:

const ImageToggleOnMouseOver = (source: string) : JSX.Element => { ... }

When I try to use it, like so, I get the above error:

return (
  <div>
    <ImageToggleOnMouseOver source='/heads_up.jpg' />
  </div>
);

When provided as source: any it works fine, but shouldn't string also work since I'm expecting to pass in a string after all?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

right type of the component should be

const ImageToggleOnMouseOver = ({source} :{source: string}) : JSX.Element => { ... }
about 4 years ago · Juan Pablo Isaza Relatório

0

You need to change the declaration in the component. It is trying to assign the props object of { source: string } to a parameter declared as (source: string). You need to change the function definition to this:

const ImageToggleOnMouseOver = ({source}: {source: string}) : JSX.Element => { ... }

By unpacking the props object and retrieving the source prop, you are able to specify the properties that you need in the function, and you are specifying the type of props.

about 4 years ago · Juan Pablo Isaza Relatório
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