CodeQL documentation

Use of incompletely initialized object

ID: js/incomplete-object-initialization
Kind: problem
Severity: error
Precision: high
Tags:
   - correctness
   - language-features
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

If a class extends another class, its constructor needs to call the super constructor before referencing this or accessing properties through super. Failure to do so will cause a runtime error.

Recommendation

Insert a super constructor call.

Example

In the following example, class A extends class B, but its constructor assigns to this.x without first invoking the super constructor, which will cause a runtime error.

class A extends B {
  constructor() { this.x = 42; }
}

To prevent the error, a super constructor call should be inserted:

class A extends B {
  constructor() { super(); this.x = 42; }
}

References