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

223
Views
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 answers
Answer question

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 Report
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!