Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda