Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda