Skip to content

Commit

Permalink
Add function overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 24, 2024
1 parent 9594d4f commit 92339b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ the store state using `canUser()`, or resolved if missing.
_Parameters_

- _resource_ `string | EntityResource`: Entity resource to check. Accepts entity object `{ kind: 'root', name: 'media', id: 1 }` or REST base as a string - `media`.
- _id_ `IdType`: Optional ID of the rest resource to check. e.g. 10.
- _id_ `IdType`: Optional ID of the resource to check, e.g. 10. Note: The argument will be ignored when using an entity object as a resource to check permissions.

_Returns_

Expand Down
17 changes: 15 additions & 2 deletions packages/core-data/src/hooks/use-resource-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@ type ResourcePermissionsResolution< IdType > = [

type EntityResource = { kind: string; name: string; id?: string | number };

function useResourcePermissions< IdType = void >(
resource: string,
id?: IdType
): ResourcePermissionsResolution< IdType >;

function useResourcePermissions< IdType = void >(
resource: EntityResource,
id?: never
): ResourcePermissionsResolution< IdType >;

/**
* Resolves resource permissions.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param resource Entity resource to check. Accepts entity object `{ kind: 'root', name: 'media', id: 1 }`
* or REST base as a string - `media`.
* @param id Optional ID of the rest resource to check. e.g. 10.
* @param id Optional ID of the resource to check, e.g. 10. Note: The argument will be ignored
* when using an entity object as a resource to check permissions.
*
* @example
* ```js
Expand Down Expand Up @@ -112,7 +123,7 @@ type EntityResource = { kind: string; name: string; id?: string | number };
* @return Entity records data.
* @template IdType
*/
export default function useResourcePermissions< IdType = void >(
function useResourcePermissions< IdType = void >(
resource: string | EntityResource,
id?: IdType
): ResourcePermissionsResolution< IdType > {
Expand Down Expand Up @@ -190,6 +201,8 @@ export default function useResourcePermissions< IdType = void >(
);
}

export default useResourcePermissions;

export function __experimentalUseResourcePermissions(
resource: string,
id?: unknown
Expand Down

0 comments on commit 92339b8

Please sign in to comment.