I have a component that is wrapped in a react-redux "connect". All the props of the component are supplied by mapStateToProps and MapDispatchToProps, so there are no "ownProps" passed to the component.
However, I get the following flow error:
Cannot create Credits element because props [1] is incompatible with empty [2].
src/components/ChildrenView/index.js
323│ />
324│
325│ {/* Credits */}
[1] 326│ <Credits />
327│
328│ {/* fullscreen pictures rhat open with onClick on tge image */}
329│ <PhotoViewer />
flow-typed/npm/react-redux_v5.x.x.js
[2] 110│ CP: $Diff<ElementConfig<Com>, RSP>,
Isn't props in 1 already empty??
I am using flow-typed as you can state in the error.
Here is the class definition and connect call:
type Props = {|
...mapStateToPropsType,
pricingModal: typeof pricingModal,
offlineModal: typeof offlineModal,
|}
class Credits extends React.Component<Props> { ... }
type mapStateToPropsType = {|
balance: number,
isVisiblePricing: boolean,
isConnected: boolean,
isVisibleOffline: boolean,
|}
const mapStateToProps = ({ parents, pricing, appState }: TP.State): mapStateToPropsType => ({
balance: parents.balance || 0,
isVisiblePricing: pricing.modalPricing,
isConnected: appState.isConnected,
isVisibleOffline: appState.modalOffline,
})
export default connect(mapStateToProps, { pricingModal, offlineModal })(Credits)
How can I remove this error (without using $FlowFixMe :/)?
Edit 1
If I make the following change on "connect" type definition on line 110 and 114 of react-redux_v5.x.x.js, type check works as expected.
Before:
declare export function connect<
Com: ComponentType<*>,
S: Object,
SP: Object,
RSP: Object,
MDP: Object,
CP: $Diff<ElementConfig<Com>, RSP>,
>(
mapStateToProps: MapStateToProps<S, SP, RSP>,
mapDispatchToProps: MDP,
): (component: Com) => ComponentType<$Diff<CP, MDP> & SP>
After:
declare export function connect<
Com: ComponentType<*>,
S: Object,
SP: Object,
RSP: Object,
MDP: Object,
CP: $Diff<$Diff<ElementConfig<Com>, RSP>, MDP>, /* <-- here */
>(
mapStateToProps: MapStateToProps<S, SP, RSP>,
mapDispatchToProps: MDP,
): (component: Com) => ComponentType<CP & SP> /* <-- here */