2017-07-26 25 views
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>'。

+0

歡迎計算器!請花些時間閱讀[幫助頁面](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

+0

我有點困惑,爲什麼你需要將這個組件連接到REDX。您不提供將redux狀態或分派連接到組件的道具的功能。您實際上可以完全刪除「connect」調用。至於錯誤,這是因爲你的道具​​設置爲「未定義」,並沒有實現任何必需的屬性。 – Simon

+0

@Simon謝謝 – pandaHT

回答

0

它看起來像你過度工程你的組件;它根本不需要connect來減少,因爲它不使用狀態或調度。此外,錯誤本身是指props的類型爲undefined,因此不會爲連接的組件實現任何必需的屬性。

這裏的簡化組件:

import * as React from 'react'; 

export default class Test extends React.Component<{}, {}> { 
    private test() {} 

    render() { 
     return(
      <h1 onClick={this.test.bind(this)}> 
       test 
      </h1> 
     ); 
    } 
} 
+1

***非常感謝您的回答*** – pandaHT

相關問題