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

261
Views
Js inmutable: cómo aplanar un mapa a un Set <número>

Tengo envíos de valor que son del tipo Map<number, Shipment> , Shipment tiene una propiedad packageIds que es del tipo Set<number> . Cuando tengo varios envíos, me gustaría revisar cada envío, obtener sus packageIds de paquete y crear un nuevo conjunto plano con todos los ID de packageIds de cada envío:

 shipments.flatMap(shipment => shipment.get('packageIds'))

Pero, si hago eso, me sale un error mecanografiado:

 TS2322: Type 'Set<number>' is not assignable to type 'Iterable<[unknown, unknown]>'. The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<[unknown, unknown], any>'.      Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<[unknown, unknown], any>'.        Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<[unknown, unknown]>'.          Type 'number' is not assignable to type '[unknown, unknown]'.

¿Cómo puedo obtener un conjunto plano al iterar sobre un mapa?

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

0

El método immutablejs flatMap de Map s devuelve otro Map . Eso no es lo que quieres. Convertir a Set antes, descartando las claves del Map :

 shipments.toSet().flatMap(shipment => shipment.get('packageIds'))
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!