-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add the necessary types to reference the preferences redux store by name #74474
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,3 +28,19 @@ export const store = createReduxStore< | |||||||||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| register( store ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| type SubsequentArgsOfFunc< F > = F extends ( arg: any, ...args: infer R ) => any | ||||||||||||||||||||||||||||||||||
| ? R | ||||||||||||||||||||||||||||||||||
| : never; | ||||||||||||||||||||||||||||||||||
| type CurriedSelectors = { | ||||||||||||||||||||||||||||||||||
| [ key in keyof typeof selectors ]: ( | ||||||||||||||||||||||||||||||||||
| ...args: SubsequentArgsOfFunc< ( typeof selectors )[ key ] > | ||||||||||||||||||||||||||||||||||
| ) => ReturnType< ( typeof selectors )[ key ] >; | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
| declare module '@wordpress/data' { | ||||||||||||||||||||||||||||||||||
| function dispatch( key: typeof STORE_NAME ): typeof actions; | ||||||||||||||||||||||||||||||||||
| function select( key: typeof STORE_NAME ): CurriedSelectors; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| function useDispatch( key: typeof STORE_NAME ): typeof actions; | ||||||||||||||||||||||||||||||||||
| function useSelect( key: typeof STORE_NAME ): CurriedSelectors; | ||||||||||||||||||||||||||||||||||
joshualip-plaudit marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+46
|
||||||||||||||||||||||||||||||||||
| type SubsequentArgsOfFunc< F > = F extends ( arg: any, ...args: infer R ) => any | |
| ? R | |
| : never; | |
| type CurriedSelectors = { | |
| [ key in keyof typeof selectors ]: ( | |
| ...args: SubsequentArgsOfFunc< ( typeof selectors )[ key ] > | |
| ) => ReturnType< ( typeof selectors )[ key ] >; | |
| }; | |
| declare module '@wordpress/data' { | |
| function dispatch( key: typeof STORE_NAME ): typeof actions; | |
| function select( key: typeof STORE_NAME ): CurriedSelectors; | |
| function useDispatch( key: typeof STORE_NAME ): typeof actions; | |
| function useSelect( key: typeof STORE_NAME ): CurriedSelectors; | |
| } |
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.
The SubsequentArgsOfFunc type helper is reinventing functionality that already exists in '@wordpress/data'. The CurriedState type in packages/data/src/types.ts (lines 146-150) provides the same functionality for currying selectors by removing the first state argument.
Consider using the built-in CurriedState type or CurriedSelectorsOf type from '@wordpress/data' instead of creating a custom implementation to maintain consistency with the framework's type system.