The code looks fine and IDE isn't showing any error but in console, there is a reference error and the code is not working.
console.log("Running...");
interface Product {
name: string;
price: number;
}
const products: Product[] = [
{name:'table',price:200,},
{name:'chair',price:40,},
{name:'book',price:20,},
]
const calcAverageProductPrice = (arr:Product[]): number => {
if(arr){
let sum:number = arr.map( item => item.price).reduce((prev, curr) => prev + curr);
let avgPrice = sum/arr.length;
return avgPrice
} else{
return 0
}
}
let result:number = calcAverageProductPrice(products)
console.log( result )
export { Product,calcAverageProductPrice }
But in console, I have this error. Error image
And also I have changed target to es6 and module es2015 from config and set the script tag type attribute to module.