From 1a82e7a1a382dca6b9ef6dfd11da06e84575f5ad Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 8 Aug 2024 13:14:59 +0200 Subject: [PATCH] DataViews: abandon the ItemRecord type (#64367) Co-authored-by: jsnajdr Co-authored-by: youknowriad --- packages/dataviews/src/normalize-fields.ts | 6 ++---- packages/dataviews/src/types.ts | 24 +++++++--------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/dataviews/src/normalize-fields.ts b/packages/dataviews/src/normalize-fields.ts index 8cd9051cbb1cc3..680749df5344a6 100644 --- a/packages/dataviews/src/normalize-fields.ts +++ b/packages/dataviews/src/normalize-fields.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import getFieldTypeDefinition from './field-types'; -import type { Field, NormalizedField, ItemRecord } from './types'; +import type { Field, NormalizedField } from './types'; /** * Apply default values and normalize the fields config. @@ -17,9 +17,7 @@ export function normalizeFields< Item >( const fieldTypeDefinition = getFieldTypeDefinition( field.type ); const getValue = - field.getValue || - // @ts-ignore - ( ( { item }: { item: ItemRecord } ) => item[ field.id ] ); + field.getValue || ( ( { item } ) => ( item as any )[ field.id ] ); const sort = field.sort ?? diff --git a/packages/dataviews/src/types.ts b/packages/dataviews/src/types.ts index 64580a089997d1..b0873e9c677f53 100644 --- a/packages/dataviews/src/types.ts +++ b/packages/dataviews/src/types.ts @@ -47,8 +47,6 @@ export type Operator = | 'isAll' | 'isNotAll'; -export type ItemRecord = Object; - export type FieldType = 'text' | 'integer'; export type ValidationContext = { @@ -128,21 +126,13 @@ export type Field< Item > = { * Filter config for the field. */ filterBy?: FilterByConfig | undefined; -} & ( Item extends ItemRecord - ? { - /** - * Callback used to retrieve the value of the field from the item. - * Defaults to `item[ field.id ]`. - */ - getValue?: ( args: { item: Item } ) => any; - } - : { - /** - * Callback used to retrieve the value of the field from the item. - * Defaults to `item[ field.id ]`. - */ - getValue: ( args: { item: Item } ) => any; - } ); + + /** + * Callback used to retrieve the value of the field from the item. + * Defaults to `item[ field.id ]`. + */ + getValue?: ( args: { item: Item } ) => any; +}; export type NormalizedField< Item > = Field< Item > & { label: string;