Skip to content
6 changes: 3 additions & 3 deletions docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,17 @@ Use the [TypeScript `import` function](https://www.typescriptlang.org/docs/handb
Since an imported type declaration can occupy an excess of the available line length and become verbose when referenced multiple times, you are encouraged to create an alias of the external type using a `@typedef` declaration at the top of the file, immediately following [the `import` groupings](/docs/contributors/code/coding-guidelines.md#imports).

```js
/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */
/** @typedef {import('@wordpress/rich-text').RichTextValue} RichTextValue */
```

Note that all custom types defined in another file can be imported.

When considering which types should be made available from a WordPress package, the `@typedef` statements in the package's entry point script should be treated as effectively the same as its public API. It is important to be aware of this, both to avoid unintentionally exposing internal types on the public interface, and as a way to expose the public types of a project.

```js
// packages/data/src/index.js
// packages/rich-text/src/can-indent-list-items.js

/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */
/** @typedef {import('./create').RichTextValue} RichTextValue */
```

In this snippet, the `@typedef` will support the usage of the previous example's `import('@wordpress/data')`.
Expand Down
2 changes: 0 additions & 2 deletions packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import useBlockSync from './use-block-sync';
import { store as blockEditorStore } from '../../store';
import { BlockRefsProvider } from './block-refs-provider';

/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */

function BlockEditorProvider( props ) {
const { children, settings } = props;

Expand Down
2 changes: 0 additions & 2 deletions packages/block-editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import useBlockSync from './use-block-sync';
import { store as blockEditorStore } from '../../store';
import { BlockRefsProvider } from './block-refs-provider';

/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */

function BlockEditorProvider( props ) {
const { children, settings } = props;

Expand Down
2 changes: 1 addition & 1 deletion packages/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ _Parameters_

_Returns_

- `WPDataRegistry`: Data registry.
- `DataRegistry`: Data registry.

### createRegistryControl

Expand Down
4 changes: 2 additions & 2 deletions packages/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { merge, isPlainObject } from 'lodash';
import defaultStorage from './storage/default';
import { combineReducers } from '../../';

/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */
/** @typedef {import('../../types').DataRegistry} DataRegistry */

/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */

Expand Down Expand Up @@ -116,7 +116,7 @@ export function createPersistenceInterface( options ) {
/**
* Data plugin to persist store state into a single storage key.
*
* @param {WPDataRegistry} registry Data registry.
* @param {DataRegistry} registry Data registry.
* @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.
*
* @return {WPDataPlugin} Data plugin.
Expand Down
23 changes: 2 additions & 21 deletions packages/data/src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,7 @@ import coreDataStore from './store';
import { createEmitter } from './utils/emitter';

/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */

/**
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.
*
* @property {Function} registerGenericStore Given a namespace key and settings
* object, registers a new generic
* store.
* @property {Function} registerStore Given a namespace key and settings
* object, registers a new namespace
* store.
* @property {Function} subscribe Given a function callback, invokes
* the callback on any change to state
* within any registered store.
* @property {Function} select Given a namespace key, returns an
* object of the store's registered
* selectors.
* @property {Function} dispatch Given a namespace key, returns an
* object of the store's registered
* action dispatchers.
*/
/** @typedef {import('./types').DataRegistry} DataRegistry */

/**
* @typedef {Object} WPDataPlugin An object of registry function overrides.
Expand All @@ -50,7 +31,7 @@ import { createEmitter } from './utils/emitter';
* @param {Object} storeConfigs Initial store configurations.
* @param {Object?} parent Parent registry.
*
* @return {WPDataRegistry} Data registry.
* @return {DataRegistry} Data registry.
*/
export function createRegistry( storeConfigs = {}, parent = null ) {
const stores = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/data/src/resolvers-cache-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { get } from 'lodash';
*/
import coreDataStore from './store';

/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */
/** @typedef {import('./types').DataRegistry} DataRegistry */

/**
* Creates a middleware handling resolvers cache invalidation.
*
* @param {WPDataRegistry} registry The registry reference for which to create
* @param {DataRegistry} registry The registry reference for which to create
* the middleware.
* @param {string} reducerKey The namespace for which to create the
* middleware.
Expand Down
Loading