If document.ElementFromPoint returns null, then this if-statement is skipped and execution falls off the end of the function, without any return. This means the function returns undefined. Callers of this function only check for null, not undefined. Specifically this if-statement makes it so that in this case the controller assumes there is an element causing "Cannot read property X of undefined" errors further down the line.
The simplest fix is simply a return null; at the end of elementFromPoint.
I would suggest enabling TypeScript's strictNullChecks option, which can guard against problems like this.
If
document.ElementFromPoint
returnsnull
, then this if-statement is skipped and execution falls off the end of the function, without any return. This means the function returnsundefined
. Callers of this function only check for null, not undefined. Specifically this if-statement makes it so that in this case the controller assumes there is an element causing "Cannot read property X of undefined" errors further down the line. The simplest fix is simply areturn null;
at the end ofelementFromPoint
.I would suggest enabling TypeScript's
strictNullChecks
option, which can guard against problems like this.