i have a function to calculate area of polygon, and here's my function
import {distance} from "mathjs"
function getArea(arrayCord) {
let triangle =[]
let area = 0.0
let a =0.0
let b =0.0
let c =0.0
let s =0.0
for (let i = 0; i < arrayCord.length-2; i++) {
a = distance(arrayCord[i],arrayCord[i+1])// p1-p2
b = distance(arrayCord[i+1],arrayCord[i+2]) //p2 - p3
c = distance(arrayCord[i],arrayCord[i+2]) //p3-p1
s = (a+b+c)/2;
triangle[i] = Math.sqrt(s*(s-a)*(s-b)*(s-c))
area+= triangle[i]
}
return area;
}
when i copy the function into a typescript class and use it, i got this error that said
Operator '+' cannot be applied to types 'number | math.BigNumber' and 'number | math.BigNumber'
the function in my typescript was
const getArea = (arryy:(number|undefined)[][]) =>{
let triangle =[]
let area = 0.0
let a:(number|BigNumber) =0.0
let b:(number|BigNumber) =0.0
let c:(number|BigNumber) =0.0
let s:(number|BigNumber) =0.0
for (let i = 0; i < arryy.length-2; i++) {
a = distance(arryy[i],arryy[i+1])// p1-p2
b = distance(arryy[i+1],arryy[i+2]) //p2 - p3
c = distance(arryy[i],arryy[i+2]) //p3-p1
s = (a+b+c)/2;
triangle[i] = Math.sqrt(s*(s-a)*(s-b)*(s-c))
area+= triangle[i]
}
return area;
}
how to solve this problem so that i can use my function on my typescript class?