diff --git a/packages/core-data/src/entities.ts b/packages/core-data/src/entities.ts index 5b5f782865f1b1..3fef6f09881477 100644 --- a/packages/core-data/src/entities.ts +++ b/packages/core-data/src/entities.ts @@ -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 }`; diff --git a/packages/core-data/src/entity-types/entities.ts b/packages/core-data/src/entity-types/entities.ts index 2f9dc6c8d1295e..ccadeeda3f001a 100644 --- a/packages/core-data/src/entity-types/entities.ts +++ b/packages/core-data/src/entity-types/entities.ts @@ -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. @@ -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; diff --git a/packages/core-data/src/entity-types/index.ts b/packages/core-data/src/entity-types/index.ts index ee5e52c6d85a2c..cfc58e06181b47 100644 --- a/packages/core-data/src/entity-types/index.ts +++ b/packages/core-data/src/entity-types/index.ts @@ -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 } } >; @@ -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' ] ] @@ -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' ]; /** diff --git a/packages/core-data/src/hooks/use-entity-record.ts b/packages/core-data/src/hooks/use-entity-record.ts index eb96cbfab24bbf..e751663f168049 100644 --- a/packages/core-data/src/hooks/use-entity-record.ts +++ b/packages/core-data/src/hooks/use-entity-record.ts @@ -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 */ diff --git a/packages/core-data/src/selectors.ts b/packages/core-data/src/selectors.ts index c039f75aaf4217..8a019fb816bc46 100644 --- a/packages/core-data/src/selectors.ts +++ b/packages/core-data/src/selectors.ts @@ -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( @@ -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(