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

224
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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