Skip to content

Commit

Permalink
Use EntityQuery type in getEntityRecord type signature
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Mar 14, 2022
1 parent 8964cb0 commit 27db5ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/core-data/src/entity-types/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ export interface EntityDeclaration {
/**
* HTTP Query parameters sent with the API request to fetch the entity records.
*/
type EntityQuery< C extends Context > = Record< string, any > & {
export type EntityQuery<
C extends Context,
Fields extends string[] | undefined = undefined
> = Record< string, any > & {
context?: C;
/**
* The requested fields. If specified, the REST API will remove from the response
* any fields not on that list.
*/
_fields?: string[];
_fields?: Fields;
};

/**
Expand Down
20 changes: 11 additions & 9 deletions packages/core-data/src/entity-types/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/**
* Internal dependencies
*/
import type { Context, Theme, Updatable, User, WpTemplate } from './index';
import type {
Context,
Theme,
Updatable,
User,
WpTemplate,
Comment,
} from './index';
import type {
DefaultContextOf,
EntityDeclaration,
EntityOf,
EntityQuery,
KeyOf,
Kind,
KindOf,
Expand Down Expand Up @@ -56,10 +64,7 @@ export type getEntityRecord = <
kind: K,
name: N,
key: KeyOf< R >,
query?: {
context?: C;
_fields?: Fields;
}
query?: EntityQuery< C, Fields >
) =>
| ( Fields extends undefined
? RecordOf< K, N, C >
Expand Down Expand Up @@ -99,10 +104,7 @@ export type getEntityRecords = <
state: State,
kind: K,
name: N,
query?: {
context?: C;
_fields?: Fields;
}
query?: EntityQuery< C, Fields >
) =>
| Array<
Fields extends undefined
Expand Down

0 comments on commit 27db5ca

Please sign in to comment.