Skip to content
Advertisement

Typescript error : A ‘super’ call must be the first statement in the constructor when a class contains initialized properties

I have the following typescript errors in my project.. let me share a sample so you can see what am dealing with.

JavaScript

This is the class that extends the controller class.. one among many others

JavaScript

Now, if I initialize the merchandisingConstants before the super call like done above. I get the following error during gulp and my page does not display anything. A super call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. I have tried all ways I can think of to fix these errors any idea of how I can go about this?

Advertisement

Answer

When you extend a class, your constructor:

  1. Must call super()
  2. Must do that before it does anything else

In your instance, you just need to re-order things:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement