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

267
Views
How to declare typescript type within a js array map?

I am trying to make the following mapping with the js array map function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

x =  state.users.map(({id, firstName, lastName}) => 
    ({id, value: `${firstName} ${lastName}`}));

However, I am getting the following typescript error Binding element 'X' implicitly has an any type for each of the properties e.g. id, firstname etc

If I try to assign a type to the properties like so:

x =  state.users.map(({id: number, firstName: string, lastName: string}) => 
    ({id, value: `${firstName} ${lastName}`}));

these are allocated as values not types.

How can I correctly assign a type to a property within a map function?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can put any:

x =  state.users.map(({id, firstName, lastName}: any) => 
    ({id, value: `${firstName} ${lastName}`}));

or with an explicit type:

x =  state.users.map(({id, firstName, lastName}: {id: string, firstName: string, lastName: string}) => 
    ({id, value: `${firstName} ${lastName}`}));
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!