我正在尝试使用 react 来重新创建我的当前组件(用纯打字稿编写),但我找不到一种方法来为扩展另一个组件的组件提供额外的道具。
export interface DataTableProps {
columns: any[];
data: any[];
}
export class DataTable extends React.Component<DataTableProps, {}> {
render() {
// -- I can use this.props.columns and this.props.data --
}
}
export class AnimalTable extends DataTable {
render() {
// -- I would need to use a this.props.onClickFunction --
}
}
我的问题是我需要给 AnimalTable 一些与 DataTable 无关的道具。我怎样才能做到这一点 ?
原文由 Emarco 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要使
DataTable
通用,以便您能够使用扩展DataTableProps
的接口: