Argument of type '(priority1: number, priority2: number) => number' is not assignable to parameter of type '(a: unknown, b: unknown) => number'

Viewed 247

I am receiving the below type error ( TypeScript - 3.7.5 ).

error TS2345: Argument of type '(priority1: number, priority2: number) => number' is not assignable to parameter of type '(a: unknown, b: unknown) => number'. Types of parameters 'priority1' and 'a' are incompatible. Type 'unknown' is not assignable to type 'number'.

Code:

public updatePriorities() {
  const priorities = this.fetchedData.map((id: IList) => id.priority);
  const uniquePriorities = [...new Set(priorities)];
  uniquePriorities.sort((priority1: number, priority2: number) => priority1 - priority2);
  const updatedPriorities = uniquePriorities.map((priority: number, index: number) => {
    return index + 1;
  });

  uniquePriorities.forEach((id: number, index: number) => {
    this.fetchedData.forEach((id1: IList) => {
      if (id1.priority === id) {
        id1.priority = updatedPriorities[index];
      }
    });
  });
}
1 Answers

I got something link it's TS design limitation so I'm afraid there is not good way to fix it. We can only wait for fix it in next versions of language

Related