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

257
Visualizações
Typescript: button type prop typescript compilation error

I have this button component:

<button
        className={internalClassName}
        onClick={onClick ?? undefined}
        disabled={disabled}
        title={title}
        style={style}
        type={type}
        {...event}
    >
        {icon && <Icon icon={icon} size={iconSize} color={iconColor} />}
        { text }
        { children }
</button>

where type is

type ButtonTypes = 'button' | 'submit' | 'reset' | undefined;

Problem is that typescript compiler complains about the prop type with:

Type 'string | undefined' is not assignable to type '"submit" | "reset" | "button" | undefined'.   Type 'string' is not assignable to type '"submit" | "reset" | "button" | undefined'.

Why it says is a string | undefined when I declared it as 'submit' | 'reset' | 'button' | undefined?

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

0

Ok, update:

It seems that the spreading prop event is the cause of the problems

{...event}
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