基础构造函数必须都具有相同的返回类型
问题描述:
我想将jsx重写为tsx。我有一个重写的反应,引导方法方法的代码:基础构造函数必须都具有相同的返回类型
import {Panel} from 'react-bootstrap';
class CustomPanel extends Panel {
constructor(props, context) {
super(props, context);
}
handleClickTitle =() => {
return;
}
}
打字稿compilator抛出异常
Base constructors must all have the same return type
如何解决呢?打字稿版本2.3.4
答
肮脏的黑客的反应,引导产业
const UntypedPanel = Panel as any;
class CustomPanel extends UntypedPanel {
handleClickTitle =() => {
return;
}
}
const TypedCustomPanel = CustomPanel as any as React.ClassicComponentClass<PanelProps>;
什么会解决你的问题(但不会导致它摆在首位)是完全忽略构造函数。只调用'super()'的构造函数是多余的。 –
如果删除构造函数我有相同的类型加密错误 MyFile.tsx(2,27):错误TS2510:基础构造函数必须都具有相同的返回类型 – Sundved