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

227
Visualizações
TypeScript this keyword context error - undefined

I have a aws lambda written in JS (TypeScript) which calls functions from different classes. I am getting undefined for the existingproducts variable even though it works fine when the REACT UI sends a call to the function. Below is my code using this keyword to reference the method of other class with current object in scope.

Entry point for the lambda

export const handler = async (upload: FileUpload, context: Context) => {
     .....code .....
     const parser = new ExcelValidator(new LookupService(), new ProductService());
     const status = await parser.performExistingUpcValidation(products as Product[], upload, workbook);
     return status

PerformExisitingUPCValidation

export class ExcelValidator {

    constructor(public lookupService: LookupService, public productService: ProductService) {

    }

    async performExistingUpcValidation(products: Product[], upload: FileUpload, workbook?: Workbook): Promise<FileStatus> {
       ...code...
       const existingProducts: any[] = await this.productService.getExistingProductsByUpcOrProductCode(productUpcs, productCodes);
       console.log("This is the exisitingProduct", existingProducts)
}

ProductServiceClass

export class ProductService {


    constructor() {
    }

    @Query(()=>[Product])
    async getExistingProductsByUpcOrProductCode(@Arg("upcs", ()=> [String]) upcs: string[], @Arg("productCodes", ()=> [String]) productCodes: string[]): Promise<Product[]> {
        console.log("I came here")
        let query = `SELECT * from table
            in (${upcs.join(",")})`;
        if(productCodes.length){
            query += ` OR "productCode" in ('${productCodes.join("','")}')`;
        }
        const results = await pool.snowflake?.execute(query);
        return results as Product[];
    }

After all the execution I am able to see

This is the exisitingProduct undefined

which means my execution does not reach the ProductServiceClass. Can someone point me to what is wrong or missing? Also any documentation/reference to read more will help alot.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

My suggestion for you is review the item below:

const results = await pool.snowflake?.execute(query);

Are you confident that snowflake is not null, because you are accepting to be undefined with help of the question mark.

about 4 years ago · Santiago Gelvez Relatório
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