Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove the required Context generic argument from entity selector types
  • Loading branch information
adamziel committed Aug 24, 2022
commit 6c8321dd0ad1ac724eaf81fb541a3d073b315c5f
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ _Parameters_

_Returns_

- Record.
- `EntityRecord | undefined`: Record.

### getEntityRecordEdits

Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ _Parameters_

_Returns_

- Record.
- `EntityRecord | undefined`: Record.

### getEntityRecordEdits

Expand Down
36 changes: 14 additions & 22 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,16 @@ export function getEntityConfig(
*/
export const getEntityRecord = createSelector(
<
EntityRecord extends ET.EntityRecord< Context >,
Context extends ET.Context
EntityRecord extends
| ET.EntityRecord< any >
| Partial< ET.EntityRecord< any > >
>(
state: State,
kind: string,
name: string,
key: EntityRecordKey,
query?: EntityQuery
) => {
): EntityRecord | undefined => {
const queriedState = get( state.entities.records, [
kind,
name,
Expand Down Expand Up @@ -272,7 +273,7 @@ export const getEntityRecord = createSelector(
const value = get( item, field );
set( filteredItem, field, value );
}
return filteredItem;
return filteredItem as EntityRecord;
}

return item;
Expand Down Expand Up @@ -311,10 +312,9 @@ export const getEntityRecord = createSelector(
* @return Record.
*/
export function __experimentalGetEntityRecordNoResolver<
EntityRecord extends ET.EntityRecord< Context >,
Context extends ET.Context
EntityRecord extends ET.EntityRecord< any >
>( state: State, kind: string, name: string, key: EntityRecordKey ) {
return getEntityRecord< EntityRecord, Context >( state, kind, name, key );
return getEntityRecord< EntityRecord >( state, kind, name, key );
}

/**
Expand All @@ -329,16 +329,13 @@ export function __experimentalGetEntityRecordNoResolver<
* @return Object with the entity's raw attributes.
*/
export const getRawEntityRecord = createSelector(
<
EntityRecord extends ET.EntityRecord< Context >,
Context extends ET.Context
>(
< EntityRecord extends ET.EntityRecord< any > >(
state: State,
kind: string,
name: string,
key: EntityRecordKey
): EntityRecord | undefined => {
const record = getEntityRecord< EntityRecord, Context >(
const record = getEntityRecord< EntityRecord >(
state,
kind,
name,
Expand Down Expand Up @@ -427,8 +424,9 @@ export function hasEntityRecords(
* @return Records.
*/
export const getEntityRecords = <
EntityRecord extends ET.EntityRecord< Context >,
Context extends ET.Context = 'edit'
EntityRecord extends
| ET.EntityRecord< any >
| Partial< ET.EntityRecord< any > >
>(
state: State,
kind: string,
Expand Down Expand Up @@ -662,10 +660,7 @@ export function hasEditsForEntityRecord(
* @return The entity record, merged with its edits.
*/
export const getEditedEntityRecord = createSelector(
<
EntityRecord extends ET.EntityRecord< Context >,
Context extends ET.Context
>(
< EntityRecord extends ET.EntityRecord< any > >(
state: State,
kind: string,
name: string,
Expand Down Expand Up @@ -1041,10 +1036,7 @@ export function getAutosaves(
*
* @return The autosave for the post and author.
*/
export function getAutosave<
EntityRecord extends ET.EntityRecord< Context >,
Context extends ET.Context
>(
export function getAutosave< EntityRecord extends ET.EntityRecord< any > >(
state: State,
postType: string,
postId: EntityRecordKey,
Expand Down