-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[@wordpress/data] Add types to the useSelect function #37239
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
base: trunk
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,26 @@ | ||
| type MapOf< T > = { [ name: string ]: T }; | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| // eslint-disable-next-line no-restricted-imports | ||
| import type { MutableRefObject } from 'react'; | ||
|
|
||
| export type MapOf< T > = { [ name: string ]: T }; | ||
|
|
||
| export type ActionCreator = Function | Generator; | ||
| export type Resolver = Function | Generator; | ||
| export type Selector = Function; | ||
|
|
||
| export type AnyConfig = ReduxStoreConfig< any, any, any >; | ||
|
|
||
| export interface SelectMapper { | ||
| ( | ||
| select: ( reference: StoreReference ) => MapOf< Function >, | ||
| registry: DataRegistry | ||
| ): unknown; | ||
| } | ||
| export type SelectChooser = SelectMapper | StoreReference; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like something very specific to the useSelect hook and not a "meaningful" type. It's just a nitpick and I don't really have experience with typescript much but I'd have avoided a named typed for this one and just inlined it personally.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this appears again in the type for |
||
| export type StoreReference = StoreDescriptor< any > | string; | ||
|
|
||
| export interface StoreInstance< Config extends AnyConfig > { | ||
| getSelectors: () => SelectorsOf< Config >; | ||
| getActions: () => ActionCreatorsOf< Config >; | ||
|
|
@@ -38,7 +53,17 @@ export interface ReduxStoreConfig< | |
| } | ||
|
|
||
| export interface DataRegistry { | ||
| __experimentalMarkListeningStores: ( | ||
| callback: ( this: DataRegistry ) => unknown, | ||
| listeningStores: MutableRefObject< unknown > | ||
| ) => unknown; | ||
| __experimentalSubscribeStore: ( | ||
| storeName: string, | ||
| listener: () => void | ||
| ) => ReturnType< DataEmitter[ 'subscribe' ] >; | ||
|
|
||
| register: ( store: StoreDescriptor< any > ) => void; | ||
| select: ( chooser: SelectChooser, deps?: unknown[] ) => any; | ||
| } | ||
|
|
||
| export interface DataEmitter { | ||
|
|
||
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 change is (weirdly) causing unit tests to fail 😅
Uh oh!
There was an error while loading. Please reload this page.
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.
Fixed by casting
deps