【问题标题】:Superclass constructor invocation should be in constructor body超类构造函数调用应该在构造函数体中
【发布时间】:2015-12-18 21:47:29
【问题描述】:

我用es6写React类构造函数,但是webstorm9编辑器出现红色高亮错误 这是代码的一部分:

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 
    };
}

super(props); 中发现错误,消息为Superclass constructor invocation should be in constructor body。 代码在 babel 中运行正常,请问如何修复?

【问题讨论】:

  • 您的代码在多个地方未正确终止。 不要在类声明中使用分号,并使用适当的缩进来查看你错过了什么
  • @Amit 类定义中的分号有什么问题?
  • 非常感谢。该代码只是该类的一部分。问题是 webstorm 错误。它已在 10.4 版中修复。
  • @RGraham:类定义不包含语句。在对象文字中使用分号或省略逗号同样是错误的

标签: error-handling reactjs webstorm ecmascript-6 superclass


【解决方案1】:

这是 WebStorm 中的一个错误,WEB-14601 在 WebStorm 10.0.4 中已修复

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多