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

233
Visualizações
Type 'string' is not assignable to type ' undefined'

I have one React Component in which I am using useState hook. I tried to set value to general onClick of menu item.

const [value,setValue]= useState("");

<Menu.Item onClick={()=>setValue("general"))>

</Menu.Item>

In another file I am passing that value.

<ChannelForm
   value={value}
/>

I am using TypeScript. Have declared prop type definition as

value?: "general" | "competitive" | "social" | "podcast";

But while passing value as a props I am getting above error.

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

0

Just to clarify - are you using an interface? See this question: Using state in react with TypeScript, for more on that.

If that doesn't help, the problem could be typescript thinks it's being passed a null value. To fix that you can use the non-null assertion operator. Read more about that in this answer: Typescript: Type 'string | undefined' is not assignable to type 'string'

If neither of those helps, let me know!

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