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

548
Views
TYPEORM TypeError: Cannot read properties of undefined (reading 'length')

I managed to make a connection to an Azure Database but at the moment of creating the tables, the server fails with this error:

[path]/node_modules/typeorm/driver/sqlserver/SqlServerQueryRunner.js:2309
                        if (!dbTables.length)
                                      ^

TypeError: Cannot read properties of undefined (reading 'length')
    at SqlServerQueryRunner.<anonymous> ([path]/node_modules/typeorm/driver/sqlserver/SqlServerQueryRunner.js:2309:39)
    at step ([path/node_modules/tslib/tslib.js:143:27)
    at Object.next ([path]/node_modules/tslib/tslib.js:124:57)
    at fulfilled ([path]/node_modules/tslib/tslib.js:114:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I tried to look for the solution but there isn't. I would be very thankful if you help me

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your dbTables variable is not defined. Compiler didn't catch this earlier because you used the non-null assertion operator (bang operator: !).

Instead of using this assertion you should adjust behaviour of your program, for example:

// check first if variable is defined
if (dbTables && dbTables.length) {}

Same but shorter:

if (dbTables?.length) {}

Your case is perfect example of why overusing non-null assertion operator can be dangerous for your code base. We should use it only when for some reason we have better knowledge of types than the compiler, which is rather rare.

about 4 years ago · Juan Pablo Isaza 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!