CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Export UseEntityRecordsWithPermissionsType
#71003
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
Export UseEntityRecordsWithPermissionsType
#71003
Conversation
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @xavier.lozano.carreras@a8c.com. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
đź‘‹ Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @xavier-lc! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
UseEntityRecordsWithPermissionsType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as described, I can't see any reason not to merge it but I'm not an expert here :)
* } >( coreDataPrivateApis ); | ||
* ``` | ||
*/ | ||
export type { UseEntityRecordsWithPermissionsType }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it feels off to export a type publicly while the actual API you're typing is private.
cc @Mamaduka: do you know if we are looking at exposing useEntityRecordsWithPermissions
publicly at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, seems odd to have exported a public type for a private API.
I don't know if we plan to make useEntityRecordsWithPermissions
public. The DataViews might evolve differently and make this hook obsolete.
cc @youknowriad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does feel odd indeed, that said I don't really consider type additions/modification/removals as breaking changes in terms of WP API, these are not available in the wp globals which means I don't mind if the type is exposed publicly at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, having a type evailable publicly, doesn't hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The end result is this
export type UseEntityRecordsWithPermissionsType = typeof useEntityRecordsWithPermissions;
which I think is counter intuitive.
Consumer code can do that easily and thus naming something as ***Type
and exporting it doesn't make much sense to me.
I do like the other changes made in this PR though.
So, my suggestions would be to not export the type as a convenience, but keep the other changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The end result is this
export type UseEntityRecordsWithPermissionsType = typeof useEntityRecordsWithPermissions;which I think is counter intuitive.
Consumer code can do that easily and thus naming something as
***Type
and exporting it doesn't make much sense to me.
@manzoorwanijk I added the UseEntityRecordsWithPermissionsType
export because useEntityRecordsWithPermissions
is only available from the outside after the unlock
call, and its type is any
, so consumer code cannot rely on typeof useEntityRecordsWithPermissions
.
If we keep the WithPermissions
export, though, this can be done from the outside:
import { unlock } from '@wordpress/admin-toolkit';
import {
WithPermissions,
useEntityRecords,
privateApis,
} from '@wordpress/core-data';
interface EntityRecordsWithPermissionsResolution< RecordType >
extends Omit<
ReturnType< typeof useEntityRecords< RecordType > >,
'records'
> {
/** The requested entity records with permissions */
records: WithPermissions< RecordType >[] | null;
}
const { useEntityRecordsWithPermissions } = unlock< {
useEntityRecordsWithPermissions: UseEntityRecordsWithPermissionsType;
} >( privateApis );
Would that be good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that instead of exporting the *Type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manzoorwanijk thanks, I've removed the export and updated the example gist and description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me now.
Unlinked contributors: xavier.lozano.carreras@a8c.com. Co-authored-by: dsas <dsas@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org> Co-authored-by: xavier-lc <xavilc@git.wordpress.org>
Unlinked contributors: xavier.lozano.carreras@a8c.com. Co-authored-by: dsas <dsas@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org> Co-authored-by: xavier-lc <xavilc@git.wordpress.org>
What?
Closes
This PR exposes the
WithPermissions
so you can get proper typing on theuseEntityRecordsWithPermissions
function after unlockingcore-data
private APIs.Why?
Unlocking
core-data
private APIs leaves you without typing for the unlocked function:How?
Add the necessary export on the
core-data
package.Testing Instructions
gutenberg-71003.patch
from this gistgit apply gutenberg-71003.patch
tryit.ts
file with your editor and check that the unlockeduseEntityRecordsWithPermissions
has proper typing: