Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda