我最近從TypeScript 2.1升級到新版本,並開始使用我的示例中的所有模仿我的React組件的錯誤。在升級之前,這種嵌套組件模式並未用於造成任何問題。升級到更新版本的TypeScript後嵌套組件的問題
組件#1:
interface ISpinnerProps{
showGlobalSpinner: boolean;
}
class SpinnerClass extends React.Component<ISpinnerProps, undefined> {
render() {
return (
// Some markup
)
}
}
export const Spinner = connect((state: State) => {
return {
showGlobalSpinner: selectors.showGlobalSpinner(state),
}
})(SpinnerClass)
部分#2:
interface IProps {
loginStatus: fb.LoginStatus
}
class AppClass extends React.Component<IProps, undefined> {
render() {
return (
// Some markup
<Spinner/> // Error is thrown here.
)
}
}
export const App = connect(mapStateToProps, actionCreators)(AppClass)
這將導致錯誤: Type '{}' is not assignable to type 'Readonly<ISpinnerProps>'. Property 'showGlobalSpinner' is missing in type '{}
編譯器要我設置的屬性父母的孩子,但這些屬性由Redux處理。有沒有人遇到類似的問題?
只要選中道具作爲可選的'''showGlobalSpinner:booelan;'我認爲會做 – WilomGfx