Skip to content

docs: add connect factory prop types (MapStateToPropsFactory, MapDispatchToPropsFactory) - #354

Open
libracapitalinvestments-rgb wants to merge 1 commit into
piotrwitek:masterfrom
libracapitalinvestments-rgb:casharmy/fix-issue-91
Open

docs: add connect factory prop types (MapStateToPropsFactory, MapDispatchToPropsFactory)#354
libracapitalinvestments-rgb wants to merge 1 commit into
piotrwitek:masterfrom
libracapitalinvestments-rgb:casharmy/fix-issue-91

Conversation

@libracapitalinvestments-rgb

Copy link
Copy Markdown

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +9 to +11
export type StateProps = ReturnType<ReturnType<typeof mapStateToPropsFactory>>;
export type DispatchProps = ReturnType<ReturnType<typeof mapDispatchToPropsFactory>>;
export type Props = StateProps & DispatchProps;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Factory types for connect props

1 participant