interface Filter {
rowAddRow: (treeData:Tree[],id:string,filterType:FilterType) =>Tree[]
}
class FilterAction implements Filter {
// I must redeclare here to ensure the correct type for id
rowAddRow(treeData:Tree[], id, filterType):Tree[] {
// do something
}
}
class Component {
constructor(props) {
super(props)
this.actions = new FilterAction()
}
// Need to redefine the function interface here as well
private actions: {
rowAddRow: (treeData:Tree[],id:string,filterType:FilterType) =>Tree[]
}
handleAdd() {
this.actions.rowAddRow()
}
}
From my perspective:
The rowAddRow
function should inherit its defined interface from the Filter
class when used within an instance of FilterAction
. This avoids the need to manually redefine the method and its interface.
Therefore, the question arises: Why is it necessary to repeat the definition of the interface and its implementation after specifying it with "implements"?