我正在尝试使用react来重新创建我的current组件(用纯打字稿编写),但我找不到一种方法来为扩展另一个的组件提供额外的道具.
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 --
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要给AnimalTable一些与DataTable无关的道具.我怎样才能做到这一点 ?
我正在创建一个扩展 React 组件的抽象类,我希望能够设置一些默认的道具,但也让扩展抽象类的组件提供自己的道具。
interface Props {
someProps: boolean
}
abstract class AbstractPureForm<P, S> extends React.Component<Props & P, S> {
...
}
Run Code Online (Sandbox Code Playgroud)
如何使用:
class Other extends AbstractPureForm<{ newProps: string}, {}> {
...
}
Run Code Online (Sandbox Code Playgroud)
现在这个设置给了我错误:
does not exist on type '(Props & P)["..."]'
Run Code Online (Sandbox Code Playgroud)