Skip to content

fix: improve data package types#61587

Open
johnhooks wants to merge 2 commits intoWordPress:trunkfrom
johnhooks:fix/improve-data-types
Open

fix: improve data package types#61587
johnhooks wants to merge 2 commits intoWordPress:trunkfrom
johnhooks:fix/improve-data-types

Conversation

@johnhooks
Copy link
Copy Markdown
Contributor

@johnhooks johnhooks commented May 11, 2024

What?

This commit improves the types in the data package.

  • Adds new types ThunkArgs and Thunk. These types are intended to be used by consumers of the data package to define their own thunks.
  • Adds the dispatch and select functions to the DataRegistry type.
  • Adds the invalidate action creators to the ActionCreatorsOf type.

Why?

This allows consumers of the data package to have more complete type safety. Also, provides access to the invalidate resolution action creators, which are useful for complex data store manipulation.

How?

Adding new types as described above.

Testing Instructions

Building the package types.

@johnhooks johnhooks requested a review from nerrad as a code owner May 11, 2024 04:29
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: johnhooks <bitmachina@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

* The store registry object.
*/
registry: DataRegistry;
};
Copy link
Copy Markdown
Contributor Author

@johnhooks johnhooks May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of usage:

import type { ThunkArgs } from "@wordpress/data";

import type { Action, Store, Item } from "./types";

export const receiveItem =
  (item: Item) =>
  async ({ dispatch, select, registry }: ThunkArgs<Action, Store>) => {
    // In this function `dispatch` and `select` are fully typed to the store and action types,
    // `registry` is fully typed, if given a fully typed store descriptor.
  };

@Mamaduka Mamaduka requested review from adamziel and tyxla May 14, 2024 07:59
@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Package] Data /packages/data labels May 14, 2024
@tyxla tyxla requested a review from jsnajdr May 14, 2024 11:19
@tyxla tyxla removed their request for review May 23, 2024 09:02
@johnhooks johnhooks force-pushed the fix/improve-data-types branch from fda218d to 68e510c Compare September 17, 2024 22:22
@johnhooks johnhooks force-pushed the fix/improve-data-types branch from 68e510c to 7408731 Compare July 20, 2025 19:25
This commit improves the types in the data package.

- Adds new types `ThunkArgs` and `Thunk`. These types are intended
  to be used by consumers of the data package to define their own
	thunks.
- Adds meta action creators to the `ActionCreatorsOf` type.
- Adds the `dispatch` and `select` functions to the `DataRegistry` type.
- Adds the `invalidate` action creators to the `ActionCreatorsOf` type.

This allows consumers of the data package to have more complete
type safety. Also, provides access to the invalidate resolution
action creators, which are useful for complex data store
manipulation.

Adding new types as described above.

Building the package types.
@johnhooks johnhooks force-pushed the fix/improve-data-types branch from 7408731 to b24c90c Compare December 11, 2025 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Data /packages/data [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants