Skip to content

Unexpected "A 'super' call must be the first statement" #1682

Closed
@eschwartz

Description

@eschwartz

From #945

The first statement in the body of a constructor must be a super call if both of the following are true:
• The containing class is a derived class.
• The constructor declares parameter properties or the containing class declares instance member variables with initializers.

These don't seem to be the only two conditions.

Consider this:

class MyView extends Backbone.View {
   private someProp:SomeType;

  constructor(options:MyOptionsType) {
     // I want to create my view with these configured events:
     options.events = {
       'click .btn-close': this.close
     };
     super(options);

     this.someProp = new SomeType();
  }
}

This results in a compiler error: error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties.

The MyView class does not contain initialized properties or parameter properties. What's going on here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions