Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Superclass constructor invocation should be in constructor body

I write React class constructor use es6, but there is a red highlight error in webstorm9 editor here is the part of code:

class AssetSelectDialog extends React.Component {
static propTypes = {
    data: React.PropTypes.any,
    pageState: React.PropTypes.string,
    pageStatus: React.PropTypes.string,
    handleCancel: React.PropTypes.func,
    handleSave: React.PropTypes.func
};

constructor(props) {
    super(props);
    this.PAGE_STATUS = {
        SHOW: 'SHOW',
        SELECT: 'SELECT'
    };
    this.state = {
        data: this.props.data || {},
        pageState: this.props.pageState || CONST.STATUS.EDIT,
        pageStatus: this.props.pageStatus || this.PAGE_STATUS.SHOW 
    };
}

there error was found in super(props); and the message is Superclass constructor invocation should be in constructor body. the code is run ok in babel., how can I fixed it?

like image 879
maxwell Avatar asked Sep 22 '15 03:09

maxwell


People also ask

Do you have to call super in constructor?

It is required if the parameterized constructor (a constructor that takes arguments) of the superclass has to be called from the subclass constructor. The parameterized super() must always be the first statement in the body of the constructor of the subclass, otherwise, we get a compilation error.

Does Super have to be the first line?

Java requires that if you call this() or super() in a constructor, it must be the first statement.

What is the first statement in the body of a constructor?

this or super Must Be the First Statement in the Constructor. Whenever we call a constructor, it must call the constructor of its base class. In addition, you can call another constructor within the class. Java enforces this rule by making the first call in a constructor be to this or super.

What happens if a super class doesn't have a constructor?

If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.


1 Answers

It's a bug in WebStorm, WEB-14601 is fixed in WebStorm 10.0.4

like image 186
lena Avatar answered Sep 21 '22 06:09

lena