-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(mapDispatchToProps): port to typescript #1760
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit eb87735:
|
✔️ Deploy Preview for react-redux-docs ready! 🔨 Explore the source changes: eb87735 🔍 Inspect the deploy log: https://app.netlify.com/sites/react-redux-docs/deploys/60e6a1e131049a0008824880 😎 Browse the preview: https://deploy-preview-1760--react-redux-docs.netlify.app |
src/connect/mapDispatchToProps.ts
Outdated
import bindActionCreators from '../utils/bindActionCreators' | ||
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps' | ||
|
||
export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) { | ||
export function whenMapDispatchToPropsIsFunction( | ||
mapDispatchToProps: ActionCreatorsMapObject | ActionCreator<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✋ It won't ever be a single action creator. It's either an object with action creators inside, a function that accepts dispatch
and returns the bound action creators object, or nothing.
You might be able to use the types I pasted into selectorFactory.ts
in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put a FixTypeLater
, I'll try to crack it today.
src/connect/mapDispatchToProps.ts
Outdated
return typeof mapDispatchToProps === 'function' | ||
? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') | ||
: undefined | ||
} | ||
|
||
export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) { | ||
export function whenMapDispatchToPropsIsMissing( | ||
mapDispatchToProps: ActionCreatorsMapObject | ActionCreator<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✋ Here, it's probably just undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoul I let the !mapDispatchToProps
check ?
@@ -20,7 +20,13 @@ export function wrapMapToPropsConstant( | |||
// could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing) | |||
// and a state object in some others (ex: whenMapStateToPropsIsMissing) | |||
// eslint-disable-next-line no-unused-vars | |||
getConstant: (dispatch: Dispatch) => { dispatch?: Dispatch } | |||
getConstant: (dispatch: Dispatch) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✋ This should probably be reworked to be more generic and flexible - maybe like:
getConstant: <T>(value: T) => ( () => T)
In other words, whatever you pass in, it returns a function that returns that thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't match with the usage of wrapMapToPropsConstant
made by whenMapDispatchToPropsIsMissing
:
wrapMapToPropsConstant((dispatch: Dispatch) => ({
dispatch,
}))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it's not just a passthrough
This is probably good enough for the moment. Thanks! |
Hi 👋
This pull request follow the typescript migration initiative #1737
Not 100% confident about type accuracy, but it's good start.