Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

ReferenceError in console in ts even after chainging the tsconfig to es6

$
0
0

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.


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>