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

173
Visualizações
Type 'number' is not assignable to type '[string | number, string]'

I got this error, when i try to format the currency value.

type CurrencyState = {
    ...,
    initialValue: [number | string, string];
}

let formatedValue = this.state.initialValue;

        if (typeof formatedValue === 'string'){
            formatedValue = parseInt(formatedValue)
        }
        formatedValue = Intl.NumberFormat("en", { style: "decimal", minimumFractionDigits: 2 }).format(formatedValue );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The way you defined initialValue's type means that it has to be an array, where its first value is either a number or a string, and its second value is a string.

In your code you check if initialValue is a string, which it can never be.

So either remove the brackets from the type, to make it number | string, or treat initialValue as an array of 2 values like so: typeof formatedValue[0] === 'string'

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