Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!