From ac2e68f9b7ff291abdc9f2709c7f5943659be4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Tue, 7 Feb 2023 09:59:08 +0100 Subject: [PATCH] Fixed incorrect type annotations in @wordpress/data (#46881) * Fixed incorrect type annotations in @wordpress/data * Prettier fix * Updated @wordpress/data readme --- packages/data/README.md | 8 ++++++++ .../data/src/components/use-dispatch/use-dispatch.js | 2 +- packages/data/src/components/use-select/index.js | 9 +++++---- packages/data/src/index.js | 4 ++++ packages/data/src/redux-store/index.js | 8 +++++--- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/data/README.md b/packages/data/README.md index 45f5054ef052e5..58d6a6976898a6 100644 --- a/packages/data/README.md +++ b/packages/data/README.md @@ -500,6 +500,10 @@ import { store as myCustomStore } from 'my-custom-store'; dispatch( myCustomStore ).setPrice( 'hammer', 9.75 ); ``` +_Type_ + +- `(storeNameOrDescriptor: StoreDescriptor|string) => Object` + _Parameters_ - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported. @@ -647,6 +651,10 @@ import { store as myCustomStore } from 'my-custom-store'; select( myCustomStore ).getPrice( 'hammer' ); ``` +_Type_ + +- `(storeNameOrDescriptor: StoreDescriptor|string) => Object` + _Parameters_ - _storeNameOrDescriptor_ `StoreDescriptor|string`: The store descriptor. The legacy calling convention of passing the store name is also supported. diff --git a/packages/data/src/components/use-dispatch/use-dispatch.js b/packages/data/src/components/use-dispatch/use-dispatch.js index 306939307be8ab..c7d270d7074bcc 100644 --- a/packages/data/src/components/use-dispatch/use-dispatch.js +++ b/packages/data/src/components/use-dispatch/use-dispatch.js @@ -5,7 +5,7 @@ import useRegistry from '../registry-provider/use-registry'; /** * @typedef {import('../../types').StoreDescriptor} StoreDescriptor - * @template StoreConfig + * @template {import('../../types').AnyConfig} StoreConfig */ /** * @typedef {import('../../types').UseDispatchReturn} UseDispatchReturn diff --git a/packages/data/src/components/use-select/index.js b/packages/data/src/components/use-select/index.js index f6adf724a32d40..db571d54b36091 100644 --- a/packages/data/src/components/use-select/index.js +++ b/packages/data/src/components/use-select/index.js @@ -21,17 +21,18 @@ const renderQueue = createQueue(); /** * @typedef {import('../../types').StoreDescriptor} StoreDescriptor - * @template C + * @template {import('../../types').AnyConfig} C */ /** * @typedef {import('../../types').ReduxStoreConfig} ReduxStoreConfig - * @template State,Actions,Selectors + * @template State,Selectors + * @template {Record} Actions */ +/** @typedef {import('../../types').MapSelect} MapSelect */ /** * @typedef {import('../../types').UseSelectReturn} UseSelectReturn - * @template T + * @template {MapSelect|StoreDescriptor} T */ -/** @typedef {import('../../types').MapSelect} MapSelect */ function Store( registry, suspense ) { const select = suspense ? registry.suspendSelect : registry.select; diff --git a/packages/data/src/index.js b/packages/data/src/index.js index 735ca5111e8baa..c33144a4ca9103 100644 --- a/packages/data/src/index.js +++ b/packages/data/src/index.js @@ -98,6 +98,8 @@ export const combineReducers = turboCombineReducers; * ``` * * @return {Object} Object containing the store's selectors. + * + * @type {(storeNameOrDescriptor: StoreDescriptor|string) => Object} */ export const select = defaultRegistry.select; @@ -154,6 +156,8 @@ export const suspendSelect = defaultRegistry.suspendSelect; * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 ); * ``` * @return {Object} Object containing the action creators. + * + * @type {(storeNameOrDescriptor: StoreDescriptor|string) => Object} */ export const dispatch = defaultRegistry.dispatch; diff --git a/packages/data/src/redux-store/index.js b/packages/data/src/redux-store/index.js index cdbc5ec59468a9..0ecaf2b941c46e 100644 --- a/packages/data/src/redux-store/index.js +++ b/packages/data/src/redux-store/index.js @@ -27,11 +27,12 @@ import * as metadataActions from './metadata/actions'; /** @typedef {import('../types').DataRegistry} DataRegistry */ /** * @typedef {import('../types').StoreDescriptor} StoreDescriptor - * @template C + * @template {import('../types').AnyConfig} C */ /** * @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig - * @template State,Actions,Selectors + * @template State,Selectors + * @template {Record} Actions */ const trimUndefinedValues = ( array ) => { @@ -100,7 +101,8 @@ function createResolversCache() { * } ); * ``` * - * @template State,Actions,Selectors + * @template State,Selectors + * @template {Record} Actions * @param {string} key Unique namespace identifier. * @param {ReduxStoreConfig} options Registered store options, with properties * describing reducer, actions, selectors,