0

I am working on a big angular project which consists of a lot of files. The null checks haven't been done consistently which results in the runtime error

Cannot read property propertyName' of undefined

It is required to be fixed. The usual way would be go through all lines of code and fix the potential instances of this issue by applying null checks. But it is going to be time intensive.

Is there a way to set Object prototype for entire project and handle this error centrally?

gliese 581 g
  • 349
  • 1
  • 4
  • 17
  • 1
    Without seeing project's codebase.... but no there is no "easy" way. – robert Jul 19 '21 at 12:32
  • 2
    The error says that you are trying to read a property from `undefined`. `undefined` does not inherit from `Object.prototype` (neither does `null`). And: Don't modify objects you don't own - manipulating the `.prototype` of a class/object you haven't defined is a _really bad practice_ that can lead to further (usually well-hidden) bugs down the road. Do yourself (and your colleagues) a favor and fix the forgotten null-/undefined-checks instead. At least the one that's causing the error to be thrown. – David Jul 19 '21 at 12:42
  • May be the accepted answer of https://stackoverflow.com/questions/14782232/how-to-avoid-cannot-read-property-of-undefined-errors is what you are looking for. – Reporter Jul 19 '21 at 12:44

0 Answers0