Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!