Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/core-data/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export const getMethodName = (
const nameSuffix =
upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );
const suffix =
usePlural && 'plural' in entityConfig && entityConfig?.plural
usePlural && 'plural' in entityConfig! && entityConfig?.plural
? upperFirst( camelCase( entityConfig.plural ) )
: nameSuffix;
return `${ prefix }${ kindPrefix }${ suffix }`;
Expand Down
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 @@ -2,7 +2,7 @@
* Internal dependencies
*/
import type { Context } from './helpers';
import { EntityRecord } from './index';
import type { EntityRecord } from './index';

/**
* HTTP Query parameters sent with the API request to fetch the entity records.
Expand Down Expand Up @@ -48,7 +48,10 @@ export type EntityType<

type RequiredConfigKeys = 'name' | 'kind' | 'key' | 'baseURLParams';

interface EntityConfig< R extends EntityRecord< C >, C extends Context > {
export interface EntityConfig<
R extends EntityRecord< C >,
C extends Context
> {
/** Path in WP REST API from which to request records of this entity. */
baseURL: string;

Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/src/entity-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export type EntityRecord<
*/
export type EntityConfigOf<
RecordOrKind extends EntityRecord | Kind,
N extends Name = undefined
N extends Name | undefined = undefined
> = RecordOrKind extends EntityRecord
? Extract< EntityConfig, { record: RecordOrKind } >
: Extract< EntityConfig, { config: { kind: RecordOrKind; name: N } } >;
Expand All @@ -131,7 +131,7 @@ export type KindOf<
*/
export type KeyOf<
RecordOrKind extends EntityRecord | Kind,
N extends Name = undefined,
N extends Name | undefined = undefined,
E extends EntityConfig = EntityConfigOf< RecordOrKind, N >
> = ( E[ 'key' ] extends keyof E[ 'record' ]
? E[ 'record' ][ E[ 'key' ] ]
Expand All @@ -146,7 +146,7 @@ export type KeyOf<
*/
export type DefaultContextOf<
RecordOrKind extends EntityRecord | Kind,
N extends Name = undefined
N extends Name | undefined = undefined
> = EntityConfigOf< RecordOrKind, N >[ 'defaultContext' ];

/**
Expand Down
1 change: 0 additions & 1 deletion packages/core-data/src/hooks/use-entity-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import deprecated from '@wordpress/deprecated';
import useQuerySelect from './use-query-select';
import { store as coreStore } from '../';
import type { Status } from './constants';
import useEntityRecords from './use-entity-records';

export interface EntityRecordResolution< RecordType > {
/** The requested entity record */
Expand Down
4 changes: 2 additions & 2 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export const __experimentalGetDirtyEntityRecords = createSelector(
const {
entities: { records },
} = state;
const dirtyRecords = [];
const dirtyRecords: DirtyEntityRecord[] = [];
( Object.keys( records ) as Kind[] ).forEach(
< K extends Kind >( kind: K ) => {
( Object.keys( records[ kind ] ) as Name[] ).forEach(
Expand Down Expand Up @@ -646,7 +646,7 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(
const {
entities: { records },
} = state;
const recordsBeingSaved = [];
const recordsBeingSaved: DirtyEntityRecord[] = [];
( Object.keys( records ) as Kind[] ).forEach(
< K extends Kind >( kind: K ) => {
( Object.keys( records[ kind ] ) as Name[] ).forEach(
Expand Down