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

217
Visualizações
TS2345: el argumento de tipo no se puede asignar al parámetro

Tengo esta declaración de valor:

const [value, setValue] = useState<PaymentOption | null>(null);

Y dentro de un componente, tengo esta función OnChange, que llama a setValue:

 onChange={(event, newValue, reason) => { setValue(newValue); const { onChange } = props; if (onChange) onChange(event, newValue, reason); }}

Pero sigo recibiendo este error (al pasar el mouse sobre la llamada setValue y durante la construcción):

TS2345: Argument of type 'string | PaymentOption | (string | PaymentOption)[] | null' is not assignable to parameter of type 'SetStateAction<PaymentOption | null>'. Type 'string' is not assignable to type 'SetStateAction<PaymentOption | null>'.

He intentado establecer el tipo en el valor nuevo, es decir,

onChange={(event, newValue: PaymentOption | null, reason) => {

Pero luego me sale este error:

Type 'string | PaymentOption | (string | PaymentOption)[] | null' is not assignable to type 'PaymentOption | null'.

Y si trato de cambiar el setValue a esto:

const [value, setValue] = useState<string | PaymentOption | (string | PaymentOption)[] | null>(null);

Y el onChange para que coincida:

onChange={(event, newValue: string | PaymentOption | (string | PaymentOption)[] | null, reason) => {

Luego, los errores desaparecen aquí, pero luego todos mis value.vars dicen:

TS2339: Property 'label' does not exist on type 'string | PaymentOption | (string | PaymentOption)[]'. Property 'label' does not exist on type 'string'.

¿Alguien tiene idea de lo que está pasando? ¿Incluso alguna pista?

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