Having an array of nullable numbers presented in the following way:
let myArray : Array<number | null> = [1,2,null,4,null,5];
let maximumOfMyArray = Math.max(...myArray); // Type null is not assignable to type number
I am content with JavaScript treating null as 0 in this scenario. There are two potential solutions that come to mind, but neither are perfect:
let myArray : Array<number | null> = [1,2,null,4,null,5];
//@ts-ignore
let maximumOfMyArray = Math.max(...myArray);
The above method does not fully resolve the issue, and:
let myArray : Array<number | null> = [1,2,null,4,null,5];
let castArray = myArray as unknown as Array<number>;
let maximumOfMyArray = Math.max(...myArray);
Is there a solution available that does not rely on these workarounds?