Skip to content

Conversation

@manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Dec 17, 2024

This PR solves two issues

  1. The core-data getCurrentUser selector's return type is set to ET.User< 'edit' >, which sets the incorrect return type with properties that don't exist on the current user object, for example, user.capabilities. The return type should rather be ET.User< 'view' > because that is what state.currentUser is, as mentioned in Convert core-data selectors from jsDoc annotations into TypeScript type signatures #40025 (comment)

Here, you can see the difference between a current user (users/me) and a normal user (users/<id>) object.

Screenshot 2024-12-17 at 4 18 23 PM
  1. The type for user.capabilities is set to Record< string, string >, which is incorrect. It should rather be Record< string, boolean >, because those capabilities come from here as pointed out in Core Data: TypeScript definitions for entity records. #38666 (comment)
image

What?

  • Fix the return type for getCurrentUser selector.
  • Fix the type for user.capabilities to be a record of booleans instead of a record of strings.

Why?

To fix the incorrect types

How?

By fixing the types

Testing Instructions

  • There is nothing really to test, you can just proof read and verify the behavior from REST API documentation.

Testing Instructions for Keyboard

Screenshots or screencast

Before After
Screenshot 2024-12-17 at 4 31 28 PM Screenshot 2024-12-17 at 4 30 01 PM

@manzoorwanijk manzoorwanijk added [Type] Code Quality Issues or PRs that relate to code quality [Package] Core data /packages/core-data labels Dec 17, 2024
@manzoorwanijk manzoorwanijk self-assigned this Dec 17, 2024
@github-actions
Copy link

github-actions bot commented Dec 17, 2024

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.

@github-actions
Copy link

github-actions bot commented Dec 27, 2024

Flaky tests detected in 8de2b23.
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/17725084572
📝 Reported issues:

@manzoorwanijk manzoorwanijk requested a review from Mamaduka July 18, 2025 16:12
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.

Sorry for the late reply, @manzoorwanijk!

The changes make sense. The REST API will use the default context view when the query argument isn't specified. The entities set the default context as part of baseURLParams, but that's not the case for the current user resolver.

https://github.com/WordPress/wordpress-develop/blob/dcc4c358f3bde4db290bb70665c14fe99cec23d1/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php#L125-L135

@manzoorwanijk manzoorwanijk merged commit eb8a06d into trunk Sep 15, 2025
68 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/ts-types-for-user branch September 15, 2025 11:21
@github-actions github-actions bot added this to the Gutenberg 21.7 milestone Sep 15, 2025
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.

3 participants