[英]How to use an abstract class as the type of a React component in TypeScript?
How can the abstract class 'Base' be used as a type definition here?抽象 class 'Base' 在这里如何用作类型定义?
abstract class Base extends React.Component { /* */ }
class A extends React.Component<{
ComponentToUse: Base
}> {
render() {
const { ComponentToUse } = this.props;
// The following line gives this compile error:
// JSX element type 'Base' does not have any construct or call signatures. ts(2604)
return (<ComponentToUse />);
}
}
Change the props from改变道具从
class A extends React.Component<{
ComponentToUse: Base
}> {
to至
class A extends React.Component<{
ComponentToUse: typeof Base
}> {
See the TS docs and this question for more information.有关更多信息,请参阅TS 文档和此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.