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

122
Views
Faltan propiedades para el tipo (mecanografiado)

En el siguiente:

 @Mutation remove_bought_products(productsToBeRemoved: Array<I.Product>) { const tmpProductsInVendingMachine: Array<I.Product> = Object.values(this.productsInVendingMachine); const reducedProductsInVendingMachine: Array<I.Product> = tmpProductsInVendingMachine.reduce((tmpProductsInVendingMachine, { id, ...rest }) => ({ ...tmpProductsInVendingMachine, ...{ [id]: { id, ...rest } } }), {}); productsToBeRemoved.forEach(({ id }) => reducedProductsInVendingMachine[id].productQty--); ...

da:

 TS2740: Type '{}' is missing the following properties from type 'Product[]': length, pop, push, concat, and 28 more. 250 | 251 | const tmpProductsInVendingMachine: Array<I.Product> = Object.values(this.productsInVendingMachine); > 252 | const reducedProductsInVendingMachine: Array<I.Product> = | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 253 | tmpProductsInVendingMachine.reduce((tmpProductsInVendingMachine, { id, ...rest }) => ({ ...tmpProductsInVendingMachine, ...{ [id]: { id, ...rest } } }), {}); 254 | productsToBeRemoved.forEach(({ id }) => reducedProductsInVendingMachine[id].productQty--);

¿Qué tipo devuelve el reductor?

Los productos son objetos que necesitan ser indexados sobre su id; p.ej

 [{ id: 1, productName: "coke", productPrice: 2, productQty: 20 }, ... ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

reducedProductsInVendingMachine no es una Array , es un Object .

Una posibilidad es convertir {} al tipo correcto en el parámetro de inicialización de Array.prototype.reduce() :

 const reducedProductsInVendingMachine = tmpProductsInVendingMachine.reduce( (tmpProductsInVendingMachine, { id, ...rest }) => ({ ...tmpProductsInVendingMachine, ...{ [id]: { id, ...rest } } }), {} as { [key: I.Product['id']]: I.Product } );

Observe cómo se compila la implementación y el tipo de variable reducedProductsInVendingMachine se infiere correctamente a { [key: I.Product['id']]: I.Product } (con I.Product['id'] resuelto como sea)

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!