Argument of type ‘number’ is not assignable to parameter of type ‘string’ – Typescript and Angular

I have this coding:

        this.arrayTemp = [];
          interface tempFull {
             num: number;
             name: string;
          }
          for (const key in group) {
              let temp = {} as tempFull;
             temp.num = parseInt(group[key].length / this.item);
             temp.name = group[key][0];
             if (temp.num >= 1){
               this.arrayTemp.push(temp);
             }
          }

The object Group is this:

{
red:[
 "red",
 "red",
 "red",
],
blue:[
 "blue",
 "blue",
 "blue",
 "blue",
],
}

And this.item could be any number

The issue tha I have if:

Argument of type 'number' is not assignable to parameter of type 'string'.

    46              temp.num = parseInt(group[key].length / parseInt(this.item));

Any help….

Answer

The type of parseInt is (value: string) => number. That is, parseInt is a function that converts strings into numbers … sometimes. However, you are passing in the result of calling the division operator on a pair of numbers, group[key].length / parseInt(this.item). A number is not a string. Remove your wrapping parseInt and replace it with a call to Math.floor, Math.ceil, or even just remove the outer call completely if you’re fine with a floating point result.