Skip to content
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

fix: improve data package types #61587

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

johnhooks
Copy link
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.

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 requested a review from nerrad as a code owner May 11, 2024 04:29
Copy link

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
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
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.

None yet

2 participants