1
import * as React from 'react';
import {connect} from 'react-redux';
interface types{
type:string;
status?:boolean;
}
export class Test extends React.Component<undefined,any> {
constructor(props:undefined){
super(props);
}
private test(){}
render(){
return(
<h1 onClick={this.test.bind(this)}>
test
</h1>
)
}
}
export default connect()(Test);
錯誤類型'typeof test'的參數不能分配給'Component <{children?:ReactNode; }&DispatchProp <any>> '
類型的參數 '的typeof測試' 不是分配給類型的參數' 成分< {兒童?: ReactNode; } & DispatchProp>'。
歡迎計算器!請花些時間閱讀[幫助頁面](http://stackoverflow.com/help),尤其是名爲[「我可以問些什麼話題?」]的章節(http://stackoverflow.com/help/)討論話題)和[「我應該避免問什麼類型的問題?」](http://stackoverflow.com/help/dont-ask)。請參閱[tour](http://stackoverflow.com/tour)並閱讀[如何提出良好問題](http://stackoverflow.com/help/how-to-ask)。最後,請學習如何創建[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 – Markus
我有點困惑,爲什麼你需要將這個組件連接到REDX。您不提供將redux狀態或分派連接到組件的道具的功能。您實際上可以完全刪除「connect」調用。至於錯誤,這是因爲你的道具設置爲「未定義」,並沒有實現任何必需的屬性。 – Simon
@Simon謝謝 – pandaHT