Skip to content

TypeScript: Fix types for core entity meta #70788

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

Merged
merged 2 commits into from
Jul 18, 2025

Conversation

manzoorwanijk
Copy link
Member

What?

Fixes #70786

Why?

The meta for the entity types like Post, User, Comment etc can be anything, not just a record of strings. Thus this PR reflects the same in the TS types.

How?

This PR changes the type of meta to be a record of unknown because that is what meta is - we don't know what type it is.

Testing Instructions

  • Use this snippet in some TS file
useSelect( select => {
	const { meta } = select( coreStore ).getEntityRecord< Post >( 'postType', 'post', 123 );

	return meta.some_key;
}, [] );
  • Confirm that the type of some_key is unknown

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@manzoorwanijk manzoorwanijk self-assigned this Jul 18, 2025
@manzoorwanijk manzoorwanijk requested a review from nerrad as a code owner July 18, 2025 15:10
@manzoorwanijk manzoorwanijk added the [Type] Code Quality Issues or PRs that relate to code quality label Jul 18, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes TypeScript type definitions for meta fields across core entity types to better reflect their actual nature. Meta fields in WordPress entities can contain various data types, not just strings.

  • Changes meta field type from Record<string, string> to Record<string, unknown> across all core entity types
  • Improves type safety by accurately representing that meta field values can be of any type
  • Addresses issue #70786 where the previous string-only typing was too restrictive

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/core-data/src/entity-types/attachment.ts Updates meta field type definition for attachment entities
packages/core-data/src/entity-types/comment.ts Updates meta field type definition for comment entities
packages/core-data/src/entity-types/nav-menu-item.ts Updates meta field type definition for navigation menu item entities
packages/core-data/src/entity-types/nav-menu.ts Updates meta field type definition for navigation menu entities
packages/core-data/src/entity-types/page.ts Updates meta field type definition for page entities
packages/core-data/src/entity-types/post-revision.ts Updates meta field type definition for post revision entities
packages/core-data/src/entity-types/post.ts Updates meta field type definition for post entities
packages/core-data/src/entity-types/term.ts Updates meta field type definition for term entities
packages/core-data/src/entity-types/user.ts Updates meta field type definition for user entities

Copy link

github-actions bot commented Jul 18, 2025

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: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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

@Mamaduka Mamaduka added the [Package] Core data /packages/core-data label Jul 18, 2025
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Makes sense ✅

@manzoorwanijk manzoorwanijk enabled auto-merge (squash) July 18, 2025 15:40
Copy link

Flaky tests detected in a3411dd.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/16374022120
📝 Reported issues:

@manzoorwanijk manzoorwanijk merged commit dd8b1ce into trunk Jul 18, 2025
79 of 95 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/ts/types-for-core-object-meta branch July 18, 2025 15:48
@github-actions github-actions bot added this to the Gutenberg 21.3 milestone Jul 18, 2025
USERSATOSHI pushed a commit to USERSATOSHI/gutenberg that referenced this pull request Jul 23, 2025
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript: meta on all the core object types is wrongly set as a record of strings
2 participants