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

[core-data]: Fix TS types for user object #68045

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

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 which 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
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: manzoorwanijk <manzoorwanijk@git.wordpress.org>

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

Copy link

Flaky tests detected in 82c1800.
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/12515957130
📝 Reported issues:

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.

1 participant