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

240
Visualizações
typescript onChange event type

how can I specify the event type for radio buttons with ReactJs and typescript

I tried this but it doesn't works for radio buttons though it works for input type="text"

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
   ....    
};
<FormControlLabel
 value="radio1"
 control={<Radio />}
 label=" radio1"
 onChange={handleChange}
/>
<FormControlLabel
 value="radio2"
 control={<Radio />}
 label="radio2"
 onChange={handleChange}
/>

Error

Type '(event: React.ChangeEvent<HTMLInputElement>) => void' is not assignable to type '(event: ChangeEvent<{}>, checked: boolean) => void'.
  Types of parameters 'event' and 'event' are incompatible.
    Type 'ChangeEvent<{}>' is not assignable to type 'ChangeEvent<HTMLInputElement>'.
      Type '{}' is missing the following properties from type 'HTMLInputElement': accept, align, alt, autocomplete, and 329 more.ts(2322)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Thanks, Any way I found the solution. <HTMLInputElement> is not assignable to radio buttons, so we can do the following to skip the built error,

(event: React.ChangeEvent<Record<string, unknown>>) {
console.log(event.target.value);
}

The above code should be used if we have radio button groups.

Otherwise, for a single radio button, this should be used

(event: React.ChangeEvent<unknown>, checked: boolean) {
  console.log(checked);
}

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