docs: add connect factory prop types (MapStateToPropsFactory, MapDispatchToPropsFactory) - #354
Conversation
There was a problem hiding this comment.
Code Review
This pull request restructures the README_SOURCE.md file and introduces a new documentation example for typing factory functions with per-instance memoization in connected-counter-with-factory-props.tsx. A critical issue was identified in the new TypeScript file where StateProps and DispatchProps circularly reference themselves, causing a compilation error. It is recommended to define these types explicitly instead of using nested ReturnType helpers.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| export type StateProps = ReturnType<ReturnType<typeof mapStateToPropsFactory>>; | ||
| export type DispatchProps = ReturnType<ReturnType<typeof mapDispatchToPropsFactory>>; | ||
| export type Props = StateProps & DispatchProps; |
There was a problem hiding this comment.
Defining StateProps and DispatchProps using ReturnType<ReturnType<typeof ...>> creates a circular type reference because the factory functions themselves are annotated with MapStateToPropsFactory<StateProps, ...> and MapDispatchToPropsFactory<DispatchProps, ...>. This results in a TypeScript compilation error: Type alias 'StateProps' circularly references itself.
To fix this, define the StateProps and DispatchProps types explicitly.
| export type StateProps = ReturnType<ReturnType<typeof mapStateToPropsFactory>>; | |
| export type DispatchProps = ReturnType<ReturnType<typeof mapDispatchToPropsFactory>>; | |
| export type Props = StateProps & DispatchProps; | |
| export type StateProps = { | |
| count: number; | |
| }; | |
| export type DispatchProps = { | |
| onIncrement: () => void; | |
| onDecrement: () => void; | |
| }; | |
| export type Props = StateProps & DispatchProps; |
Adds documentation and example code for using factory types with react-redux's connect function, including MapStateToPropsFactory and MapDispatchToPropsFactory for per-instance memoization with selectors. Closes #91