'Variable 'minSum' is used before being assigned

let arrSort: number[] = arr.sort(), minSum: number;
   arrSort.forEach((a, b) => {
     if(b > 0){
       minSum += minSum + a;
       console.log(b)
     }
   })
   console.log(minSum); // Variable 'minSum' is used before being assigned. 

minSum is defined on top but typescript still throws an error saying it s not assigned



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source