基础构造函数必须都具有相同的返回类型

时间:2017-08-10 05:22:01

标签: reactjs typescript ecmascript-6 react-bootstrap

我想将jsx重写为tsx。我有一个代码,从react-bootstrap方法重写方法:

import {Panel} from 'react-bootstrap';
class CustomPanel extends Panel {
    constructor(props, context) {
        super(props, context);
    }

    handleClickTitle = () => {
        return;
    }
}

打字稿编译器抛出异常

 Base constructors must all have the same return type

如何解决?打字稿版本2.3.4

1 个答案:

答案 0 :(得分:1)

反应引导继承的肮脏黑客

const UntypedPanel = Panel as any;
class CustomPanel extends UntypedPanel {
    handleClickTitle = () => {
        return;
    }
}
const TypedCustomPanel = CustomPanel as any as React.ClassicComponentClass<PanelProps>;