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

161
Views
Typescript Math.max - group by find max

I'm trying to find the max csBasisPerUnit for each csId in my array. In typescript I receive an error on ...csBasisPerUnit in the last line on Math.max(...csBasisPerUnit):

Type 'unknown' must have a 'Symbol.iterator' method that returns an iterator

What do I need to put here or what is it telling me? I don't understand this.

My interface looks like this:

export interface IGroupBy {
  csId: number | null,
  csBasisPerUnit: number | null
}

Here is the function:

const groupBy = <IGroupBy, K extends keyof IGroupBy>(list: IGroupBy[], getKey: (item: IGroupBy) => K) => {
  const reducedArr = list.reduce((previous, currentItem) => {
    const group = getKey(currentItem);
    if (!previous[group]) previous[group] = [];
    previous[group].push(currentItem);
    return previous;
  }, {} as Record<K, IGroupBy[]>)

  const arr = Object.entries(reducedArr);
arr.reduce((c, [k, csBasisPerUnit]) => Object.assign(c, {[k]: Math.max(...csBasisPerUnit)}), {});
about 4 years ago · Juan Pablo Isaza
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!