From 8a908681386ddd641caef19c08f586b4bd495bd5 Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Sun, 7 Jun 2026 09:03:28 -0500 Subject: [PATCH] fix: improve ts perf with feature maps --- packages/angular-table/src/injectTable.ts | 4 +- .../src/core/table/constructTable.ts | 2 +- packages/table-core/src/types/Cell.ts | 26 ++--- packages/table-core/src/types/Column.ts | 65 ++++-------- packages/table-core/src/types/ColumnDef.ts | 57 ++++------ packages/table-core/src/types/Header.ts | 30 +++--- packages/table-core/src/types/Row.ts | 46 ++++---- packages/table-core/src/types/RowModel.ts | 89 +++++++--------- packages/table-core/src/types/RowModelFns.ts | 36 +++---- packages/table-core/src/types/Table.ts | 80 +++++--------- .../table-core/src/types/TableFeatures.ts | 12 +++ packages/table-core/src/types/TableOptions.ts | 100 +++++++----------- packages/table-core/src/types/TableState.ts | 77 +++++--------- 13 files changed, 244 insertions(+), 380 deletions(-) diff --git a/packages/angular-table/src/injectTable.ts b/packages/angular-table/src/injectTable.ts index 7803f2be20..b82afc6c21 100644 --- a/packages/angular-table/src/injectTable.ts +++ b/packages/angular-table/src/injectTable.ts @@ -55,11 +55,11 @@ function createStateProxy< const getSnapshot = () => { const snapshot = {} as TableState const stateKeys = Object.keys(table.initialState) as Array< - keyof TableState + string & keyof TableState > for (const key of stateKeys) { - snapshot[key] = table.atoms[key].get() + ;(snapshot as Record)[key] = table.atoms[key].get() } return snapshot diff --git a/packages/table-core/src/core/table/constructTable.ts b/packages/table-core/src/core/table/constructTable.ts index 94ed145471..edb524a88d 100644 --- a/packages/table-core/src/core/table/constructTable.ts +++ b/packages/table-core/src/core/table/constructTable.ts @@ -133,7 +133,7 @@ export function constructTable< const snapshot = {} as TableState for (let i = 0; i < stateKeys.length; i++) { const key = stateKeys[i]! - snapshot[key] = table.atoms[key].get() + ;(snapshot as Record)[key] = table.atoms[key].get() } return snapshot }, diff --git a/packages/table-core/src/types/Cell.ts b/packages/table-core/src/types/Cell.ts index 0f9480f954..4386a9b321 100644 --- a/packages/table-core/src/types/Cell.ts +++ b/packages/table-core/src/types/Cell.ts @@ -1,6 +1,10 @@ import type { Cell_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types' -import type { CellData, RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { CellData, RowData } from './type-utils' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' import type { Cell_Cell } from '../core/cells/coreCellsFeature.types' /** @@ -19,23 +23,15 @@ export interface Cell_Core< TValue extends CellData = CellData, > extends Cell_Cell {} +export interface Cell_FeatureMap { + columnGroupingFeature: Cell_ColumnGrouping +} + export type Cell< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, > = Cell_Cell & - UnionToIntersection< - 'columnGroupingFeature' extends keyof TFeatures - ? Cell_ColumnGrouping - : never - > & + ExtractFeatureMapTypes & ExtractFeatureTypes<'Cell', TFeatures> & Cell_Plugins - -// export type Cell< -// TFeatures extends TableFeatures, -// TData extends RowData, -// TValue extends CellData = CellData, -// > = Cell_Core & -// ExtractFeatureTypes & -// Cell_Plugins diff --git a/packages/table-core/src/types/Column.ts b/packages/table-core/src/types/Column.ts index a9553e8231..56e3a707b3 100644 --- a/packages/table-core/src/types/Column.ts +++ b/packages/table-core/src/types/Column.ts @@ -9,8 +9,12 @@ import type { Column_ColumnResizing } from '../features/column-resizing/columnRe import type { Column_ColumnSizing } from '../features/column-sizing/columnSizingFeature.types' import type { Column_ColumnVisibility } from '../features/column-visibility/columnVisibilityFeature.types' import type { ColumnDefBase_All } from './ColumnDef' -import type { RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { RowData } from './type-utils' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' import type { Column_Column } from '../core/columns/coreColumnsFeature.types' /** @@ -29,54 +33,31 @@ export interface Column_Core< TValue = unknown, > extends Column_Column {} +export interface Column_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFacetingFeature: Column_ColumnFaceting + columnFilteringFeature: Column_ColumnFiltering + columnGroupingFeature: Column_ColumnGrouping + columnOrderingFeature: Column_ColumnOrdering + columnPinningFeature: Column_ColumnPinning + columnResizingFeature: Column_ColumnResizing + columnSizingFeature: Column_ColumnSizing + columnVisibilityFeature: Column_ColumnVisibility + globalFilteringFeature: Column_GlobalFiltering + rowSortingFeature: Column_RowSorting +} + export type Column< TFeatures extends TableFeatures, TData extends RowData, TValue = unknown, > = Column_Core & - UnionToIntersection< - | ('columnFacetingFeature' extends keyof TFeatures - ? Column_ColumnFaceting - : never) - | ('columnFilteringFeature' extends keyof TFeatures - ? Column_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? Column_ColumnGrouping - : never) - | ('columnOrderingFeature' extends keyof TFeatures - ? Column_ColumnOrdering - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? Column_ColumnPinning - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? Column_ColumnResizing - : never) - | ('columnSizingFeature' extends keyof TFeatures - ? Column_ColumnSizing - : never) - | ('columnVisibilityFeature' extends keyof TFeatures - ? Column_ColumnVisibility - : never) - | ('globalFilteringFeature' extends keyof TFeatures - ? Column_GlobalFiltering - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? Column_RowSorting - : never) - > & + ExtractFeatureMapTypes> & ExtractFeatureTypes<'Column', TFeatures> & Column_Plugins -// export type Column< -// TFeatures extends TableFeatures, -// TData extends RowData, -// TValue = unknown, -// > = Column_Core & -// ExtractFeatureTypes<'Column', TFeatures> & -// Column_Plugins - export type Column_Internal< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/types/ColumnDef.ts b/packages/table-core/src/types/ColumnDef.ts index b60ddc0173..6520c52dd9 100644 --- a/packages/table-core/src/types/ColumnDef.ts +++ b/packages/table-core/src/types/ColumnDef.ts @@ -1,5 +1,9 @@ import type { CellData, RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' import type { CellContext } from '../core/cells/coreCellsFeature.types' import type { HeaderContext } from '../core/headers/coreHeadersFeature.types' import type { ColumnDef_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types' @@ -110,48 +114,33 @@ interface ColumnDefBase_Core< meta?: ColumnMeta } +export interface ColumnDef_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, + TValue extends CellData, +> { + columnVisibilityFeature: ColumnDef_ColumnVisibility + columnPinningFeature: ColumnDef_ColumnPinning + columnFilteringFeature: ColumnDef_ColumnFiltering + globalFilteringFeature: ColumnDef_GlobalFiltering + rowSortingFeature: ColumnDef_RowSorting + columnGroupingFeature: ColumnDef_ColumnGrouping + columnSizingFeature: ColumnDef_ColumnSizing + columnResizingFeature: ColumnDef_ColumnResizing +} + export type ColumnDefBase< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, > = ColumnDefBase_Core & - UnionToIntersection< - | ('columnVisibilityFeature' extends keyof TFeatures - ? ColumnDef_ColumnVisibility - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? ColumnDef_ColumnPinning - : never) - | ('columnFilteringFeature' extends keyof TFeatures - ? ColumnDef_ColumnFiltering - : never) - | ('globalFilteringFeature' extends keyof TFeatures - ? ColumnDef_GlobalFiltering - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? ColumnDef_RowSorting - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? ColumnDef_ColumnGrouping - : never) - | ('columnSizingFeature' extends keyof TFeatures - ? ColumnDef_ColumnSizing - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? ColumnDef_ColumnResizing - : never) + ExtractFeatureMapTypes< + TFeatures, + ColumnDef_FeatureMap > & ExtractFeatureTypes<'ColumnDef', TFeatures> & ColumnDef_Plugins -// export type ColumnDefBase< -// TFeatures extends TableFeatures, -// TData extends RowData, -// TValue extends CellData = CellData, -// > = ColumnDefBase_Core & -// ExtractFeatureTypes<'ColumnDef', TFeatures> & -// ColumnDef_Plugins - export type ColumnDefBase_All< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/types/Header.ts b/packages/table-core/src/types/Header.ts index d11e7a8e7f..f5c3c0fb86 100644 --- a/packages/table-core/src/types/Header.ts +++ b/packages/table-core/src/types/Header.ts @@ -1,6 +1,10 @@ import type { Header_ColumnSizing } from '../features/column-sizing/columnSizingFeature.types' -import type { CellData, RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { CellData, RowData } from './type-utils' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' import type { Header_Header } from '../core/headers/coreHeadersFeature.types' import type { Header_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types' @@ -20,26 +24,16 @@ export interface Header_Core< TValue extends CellData = CellData, > extends Header_Header {} +export interface Header_FeatureMap { + columnSizingFeature: Header_ColumnSizing + columnResizingFeature: Header_ColumnResizing +} + export type Header< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, > = Header_Core & - UnionToIntersection< - | ('columnSizingFeature' extends keyof TFeatures - ? Header_ColumnSizing - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? Header_ColumnResizing - : never) - > & + ExtractFeatureMapTypes & ExtractFeatureTypes<'Header', TFeatures> & Header_Plugins - -// export type Header< -// TFeatures extends TableFeatures, -// TData extends RowData, -// TValue extends CellData = CellData, -// > = Header_Core & -// ExtractFeatureTypes<'Header', TFeatures> & -// Header_Plugins diff --git a/packages/table-core/src/types/Row.ts b/packages/table-core/src/types/Row.ts index 7ce3e0c127..dc638287a9 100644 --- a/packages/table-core/src/types/Row.ts +++ b/packages/table-core/src/types/Row.ts @@ -2,11 +2,15 @@ import type { Row_ColumnVisibility } from '../features/column-visibility/columnV import type { Row_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types' import type { Row_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types' import type { Row_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types' -import type { RowData, UnionToIntersection } from './type-utils' +import type { RowData } from './type-utils' import type { Row_RowExpanding } from '../features/row-expanding/rowExpandingFeature.types' import type { Row_RowPinning } from '../features/row-pinning/rowPinningFeature.types' import type { Row_RowSelection } from '../features/row-selection/rowSelectionFeature.types' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' import type { Row_Row } from '../core/rows/coreRowsFeature.types' /** @@ -23,33 +27,23 @@ export interface Row_Core< TData extends RowData, > extends Row_Row {} +export interface Row_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFilteringFeature: Row_ColumnFiltering + columnGroupingFeature: Row_ColumnGrouping + columnPinningFeature: Row_ColumnPinning + columnVisibilityFeature: Row_ColumnVisibility + rowExpandingFeature: Row_RowExpanding + rowPinningFeature: Row_RowPinning + rowSelectionFeature: Row_RowSelection +} + export type Row< TFeatures extends TableFeatures, TData extends RowData, > = Row_Core & - UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? Row_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? Row_ColumnGrouping - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? Row_ColumnPinning - : never) - | ('columnVisibilityFeature' extends keyof TFeatures - ? Row_ColumnVisibility - : never) - | ('rowExpandingFeature' extends keyof TFeatures ? Row_RowExpanding : never) - | ('rowPinningFeature' extends keyof TFeatures ? Row_RowPinning : never) - | ('rowSelectionFeature' extends keyof TFeatures ? Row_RowSelection : never) - > & + ExtractFeatureMapTypes> & ExtractFeatureTypes<'Row', TFeatures> & Row_Plugins - -// export type Row< -// TFeatures extends TableFeatures, -// TData extends RowData, -// > = Row_Core & -// ExtractFeatureTypes<'Row', TFeatures> & -// Row_Plugins diff --git a/packages/table-core/src/types/RowModel.ts b/packages/table-core/src/types/RowModel.ts index bb5797be5c..341845fd62 100644 --- a/packages/table-core/src/types/RowModel.ts +++ b/packages/table-core/src/types/RowModel.ts @@ -27,8 +27,12 @@ import type { CachedRowModel_Sorted, CreateRowModel_Sorted, } from '../features/row-sorting/rowSortingFeature.types' -import type { RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { RowData } from './type-utils' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' /** * Use this interface as a target for declaration merging to add your own plugin properties. @@ -39,40 +43,29 @@ export interface CreateRowModels_Plugins< TData extends RowData, > {} +export interface CreateRowModels_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFacetingFeature: CreateRowModel_Faceted + columnFilteringFeature: CreateRowModel_Filtered + rowExpandingFeature: CreateRowModel_Expanded + columnGroupingFeature: CreateRowModel_Grouped + rowPaginationFeature: CreateRowModel_Paginated + rowSortingFeature: CreateRowModel_Sorted +} + export type CreateRowModels< TFeatures extends TableFeatures, TData extends RowData, > = CreateRowModel_Core & - UnionToIntersection< - | ('columnFacetingFeature' extends keyof TFeatures - ? CreateRowModel_Faceted - : never) - | ('columnFilteringFeature' extends keyof TFeatures - ? CreateRowModel_Filtered - : never) - | ('rowExpandingFeature' extends keyof TFeatures - ? CreateRowModel_Expanded - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? CreateRowModel_Grouped - : never) - | ('rowPaginationFeature' extends keyof TFeatures - ? CreateRowModel_Paginated - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? CreateRowModel_Sorted - : never) + ExtractFeatureMapTypes< + TFeatures, + CreateRowModels_FeatureMap > & ExtractFeatureTypes<'CreateRowModels', TFeatures> & CreateRowModels_Plugins -// export type CreateRowModels< -// TFeatures extends TableFeatures, -// TData extends RowData, -// > = CreateRowModel_Core & -// ExtractFeatureTypes<'CreateRowModels', TFeatures> & -// CreateRowModels_Plugins - export type CreateRowModels_All< TFeatures extends TableFeatures, TData extends RowData, @@ -89,40 +82,30 @@ export interface CachedRowModels_Plugins< TData extends RowData, > {} +export interface CachedRowModels_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFacetingFeature: CachedRowModel_Faceted + columnFilteringFeature: CachedRowModel_Filtered + rowExpandingFeature: CachedRowModel_Expanded + columnGroupingFeature: CachedRowModel_Grouped + rowPaginationFeature: CachedRowModel_Paginated + rowSortingFeature: CachedRowModel_Sorted +} + export type CachedRowModels< TFeatures extends TableFeatures, TData extends RowData, > = { CachedRowModel_Core: () => RowModel -} & UnionToIntersection< - | ('columnFacetingFeature' extends keyof TFeatures - ? CachedRowModel_Faceted - : never) - | ('columnFilteringFeature' extends keyof TFeatures - ? CachedRowModel_Filtered - : never) - | ('rowExpandingFeature' extends keyof TFeatures - ? CachedRowModel_Expanded - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? CachedRowModel_Grouped - : never) - | ('rowPaginationFeature' extends keyof TFeatures - ? CachedRowModel_Paginated - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? CachedRowModel_Sorted - : never) +} & ExtractFeatureMapTypes< + TFeatures, + CachedRowModels_FeatureMap > & ExtractFeatureTypes<'CachedRowModel', TFeatures> & CachedRowModels_Plugins -// export type CachedRowModels< -// TFeatures extends TableFeatures, -// TData extends RowData, -// > = ExtractFeatureTypes<'CachedRowModel', TFeatures> & -// CachedRowModels_Plugins - export type CachedRowModel_All< TFeatures extends TableFeatures, TData extends RowData = any, diff --git a/packages/table-core/src/types/RowModelFns.ts b/packages/table-core/src/types/RowModelFns.ts index aefcfd86df..07c3e60c9a 100644 --- a/packages/table-core/src/types/RowModelFns.ts +++ b/packages/table-core/src/types/RowModelFns.ts @@ -1,8 +1,12 @@ import type { RowModelFns_RowSorting } from '../features/row-sorting/rowSortingFeature.types' import type { RowModelFns_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types' -import type { RowData, UnionToIntersection } from './type-utils' +import type { RowData } from './type-utils' import type { RowModelFns_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' /** * Use this interface as a target for declaration merging to add your own plugin properties. @@ -15,32 +19,24 @@ export interface RowModelFns_Plugins< export interface RowModelFns_Core {} +export interface RowModelFns_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFilteringFeature: RowModelFns_ColumnFiltering + columnGroupingFeature: RowModelFns_ColumnGrouping + rowSortingFeature: RowModelFns_RowSorting +} + export type RowModelFns< TFeatures extends TableFeatures, TData extends RowData, > = Partial< - UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? RowModelFns_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? RowModelFns_ColumnGrouping - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? RowModelFns_RowSorting - : never) - > & + ExtractFeatureMapTypes> & ExtractFeatureTypes<'RowModelFns', TFeatures> & RowModelFns_Plugins > -// export type RowModelFns< -// TFeatures extends TableFeatures, -// TData extends RowData, -// > = RowModelFns_Core & -// ExtractFeatureTypes<'RowModelFns', TFeatures> & -// RowModelFns_Plugins - export type RowModelFns_All< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/types/Table.ts b/packages/table-core/src/types/Table.ts index fe1466a9b4..a6b8de6883 100644 --- a/packages/table-core/src/types/Table.ts +++ b/packages/table-core/src/types/Table.ts @@ -17,8 +17,12 @@ import type { Table_RowModels } from '../core/row-models/coreRowModelsFeature.ty import type { CachedRowModel_All, CreateRowModels_All } from './RowModel' import type { RowModelFns_All } from './RowModelFns' import type { TableState_All } from './TableState' -import type { RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { RowData } from './type-utils' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' import type { Table_Columns } from '../core/columns/coreColumnsFeature.types' import type { Table_Headers } from '../core/headers/coreHeadersFeature.types' import type { Table_Rows } from '../core/rows/coreRowsFeature.types' @@ -52,6 +56,26 @@ export type Table_Core< Table_RowModels & Table_Headers +export interface Table_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFilteringFeature: Table_ColumnFiltering + columnGroupingFeature: Table_ColumnGrouping + columnOrderingFeature: Table_ColumnOrdering + columnPinningFeature: Table_ColumnPinning + columnResizingFeature: Table_ColumnResizing + columnSizingFeature: Table_ColumnSizing + columnVisibilityFeature: Table_ColumnVisibility + columnFacetingFeature: Table_ColumnFaceting + globalFilteringFeature: Table_GlobalFiltering + rowExpandingFeature: Table_RowExpanding + rowPaginationFeature: Table_RowPagination + rowPinningFeature: Table_RowPinning + rowSelectionFeature: Table_RowSelection + rowSortingFeature: Table_RowSorting +} + /** * The table object that includes both the core table functionality and the features that are enabled via the `features` table option. */ @@ -59,60 +83,10 @@ export type Table< TFeatures extends TableFeatures, TData extends RowData, > = Table_Core & - UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? Table_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? Table_ColumnGrouping - : never) - | ('columnOrderingFeature' extends keyof TFeatures - ? Table_ColumnOrdering - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? Table_ColumnPinning - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? Table_ColumnResizing - : never) - | ('columnSizingFeature' extends keyof TFeatures - ? Table_ColumnSizing - : never) - | ('columnVisibilityFeature' extends keyof TFeatures - ? Table_ColumnVisibility - : never) - | ('columnFacetingFeature' extends keyof TFeatures - ? Table_ColumnFaceting - : never) - | ('globalFilteringFeature' extends keyof TFeatures - ? Table_GlobalFiltering - : never) - | ('rowExpandingFeature' extends keyof TFeatures - ? Table_RowExpanding - : never) - | ('rowPaginationFeature' extends keyof TFeatures - ? Table_RowPagination - : never) - | ('rowPinningFeature' extends keyof TFeatures - ? Table_RowPinning - : never) - | ('rowSelectionFeature' extends keyof TFeatures - ? Table_RowSelection - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? Table_RowSorting - : never) - > & + ExtractFeatureMapTypes> & ExtractFeatureTypes<'Table', TFeatures> & Table_Plugins -// export type Table< -// TFeatures extends TableFeatures, -// TData extends RowData, -// > = Table_Core & -// ExtractFeatureTypes<'Table', TFeatures> & -// Table_Plugins - export type Table_Internal< TFeatures extends TableFeatures, TData extends RowData = any, diff --git a/packages/table-core/src/types/TableFeatures.ts b/packages/table-core/src/types/TableFeatures.ts index d55702f6e4..9813a3d1ed 100644 --- a/packages/table-core/src/types/TableFeatures.ts +++ b/packages/table-core/src/types/TableFeatures.ts @@ -22,6 +22,18 @@ export type ExtractFeatureTypes< }[keyof TFeatures] > +type IsAny = 0 extends 1 & T ? true : false + +export type ExtractFeatureMapTypes< + TFeatures extends TableFeatures, + TFeatureMap extends object, +> = + IsAny extends true + ? UnionToIntersection + : UnionToIntersection< + TFeatureMap[Extract] + > + export interface FeatureConstructors { CachedRowModel?: any Cell?: any diff --git a/packages/table-core/src/types/TableOptions.ts b/packages/table-core/src/types/TableOptions.ts index 67f46dbe4f..36fd0aebff 100644 --- a/packages/table-core/src/types/TableOptions.ts +++ b/packages/table-core/src/types/TableOptions.ts @@ -17,7 +17,11 @@ import type { TableOptions_RowPinning } from '../features/row-pinning/rowPinning import type { TableOptions_RowSelection } from '../features/row-selection/rowSelectionFeature.types' import type { TableOptions_RowSorting } from '../features/row-sorting/rowSortingFeature.types' import type { RowData, UnionToIntersection } from './type-utils' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' export interface TableOptions_Plugins< TFeatures extends TableFeatures, @@ -52,6 +56,35 @@ export type DebugOptions = { debugTable?: boolean } & DebugKeysFor +export interface TableOptions_FeatureMap< + TFeatures extends TableFeatures, + TData extends RowData, +> { + columnFilteringFeature: TableOptions_ColumnFiltering + columnGroupingFeature: TableOptions_ColumnGrouping + columnOrderingFeature: TableOptions_ColumnOrdering + columnPinningFeature: TableOptions_ColumnPinning + columnResizingFeature: TableOptions_ColumnResizing + columnSizingFeature: TableOptions_ColumnSizing + columnVisibilityFeature: TableOptions_ColumnVisibility + globalFilteringFeature: TableOptions_GlobalFiltering + rowExpandingFeature: TableOptions_RowExpanding + rowPaginationFeature: TableOptions_RowPagination + rowPinningFeature: TableOptions_RowPinning + rowSelectionFeature: TableOptions_RowSelection + rowSortingFeature: TableOptions_RowSorting +} + +export type TableOptions_FeatureMap_All< + TFeatures extends TableFeatures, + TData extends RowData, +> = UnionToIntersection< + TableOptions_FeatureMap[keyof TableOptions_FeatureMap< + TFeatures, + TData + >] +> + /** * Complete table options for a specific feature set. * @@ -63,58 +96,11 @@ export type TableOptions< TFeatures extends TableFeatures, TData extends RowData, > = TableOptions_Core & - UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? TableOptions_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? TableOptions_ColumnGrouping - : never) - | ('columnOrderingFeature' extends keyof TFeatures - ? TableOptions_ColumnOrdering - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? TableOptions_ColumnPinning - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? TableOptions_ColumnResizing - : never) - | ('columnSizingFeature' extends keyof TFeatures - ? TableOptions_ColumnSizing - : never) - | ('columnVisibilityFeature' extends keyof TFeatures - ? TableOptions_ColumnVisibility - : never) - | ('globalFilteringFeature' extends keyof TFeatures - ? TableOptions_GlobalFiltering - : never) - | ('rowExpandingFeature' extends keyof TFeatures - ? TableOptions_RowExpanding - : never) - | ('rowPaginationFeature' extends keyof TFeatures - ? TableOptions_RowPagination - : never) - | ('rowPinningFeature' extends keyof TFeatures - ? TableOptions_RowPinning - : never) - | ('rowSelectionFeature' extends keyof TFeatures - ? TableOptions_RowSelection - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? TableOptions_RowSorting - : never) - > & + ExtractFeatureMapTypes> & ExtractFeatureTypes<'TableOptions', TFeatures> & TableOptions_Plugins & DebugOptions -// export type TableOptions< -// TFeatures extends TableFeatures, -// TData extends RowData, -// > = TableOptions_Core & -// ExtractFeatureTypes<'TableOptions', TFeatures> & -// TableOptions_Plugins - /** * Internal broad option shape used where feature code may need to read options * from features that are not present in the current generic feature set. @@ -123,18 +109,4 @@ export type TableOptions_All< TFeatures extends TableFeatures, TData extends RowData, > = TableOptions_Core & - Partial< - TableOptions_ColumnFiltering & - TableOptions_ColumnGrouping & - TableOptions_ColumnOrdering & - TableOptions_ColumnPinning & - TableOptions_ColumnResizing & - TableOptions_ColumnSizing & - TableOptions_ColumnVisibility & - TableOptions_GlobalFiltering & - TableOptions_RowExpanding & - TableOptions_RowPagination & - TableOptions_RowPinning & - TableOptions_RowSelection & - TableOptions_RowSorting - > + Partial> diff --git a/packages/table-core/src/types/TableState.ts b/packages/table-core/src/types/TableState.ts index 98a3972693..188aae77c7 100644 --- a/packages/table-core/src/types/TableState.ts +++ b/packages/table-core/src/types/TableState.ts @@ -1,4 +1,3 @@ -import type { UnionToIntersection } from './type-utils' import type { TableState_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types' import type { TableState_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types' import type { TableState_ColumnOrdering } from '../features/column-ordering/columnOrderingFeature.types' @@ -12,7 +11,11 @@ import type { TableState_RowPagination } from '../features/row-pagination/rowPag import type { TableState_RowPinning } from '../features/row-pinning/rowPinningFeature.types' import type { TableState_RowSelection } from '../features/row-selection/rowSelectionFeature.types' import type { TableState_RowSorting } from '../features/row-sorting/rowSortingFeature.types' -import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' +import type { + ExtractFeatureMapTypes, + ExtractFeatureTypes, + TableFeatures, +} from './TableFeatures' /** * Use this interface as a target for declaration merging to add your own state properties. @@ -20,62 +23,32 @@ import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures' */ export interface TableState_Plugins {} +export interface TableState_FeatureMap { + columnFilteringFeature: TableState_ColumnFiltering + columnGroupingFeature: TableState_ColumnGrouping + columnOrderingFeature: TableState_ColumnOrdering + columnPinningFeature: TableState_ColumnPinning + columnResizingFeature: TableState_ColumnResizing + columnSizingFeature: TableState_ColumnSizing + columnVisibilityFeature: TableState_ColumnVisibility + globalFilteringFeature: TableState_GlobalFiltering + rowExpandingFeature: TableState_RowExpanding + rowPaginationFeature: TableState_RowPagination + rowPinningFeature: TableState_RowPinning + rowSelectionFeature: TableState_RowSelection + rowSortingFeature: TableState_RowSorting +} + /** * Complete table state for a specific feature set. * * State slices are included only when their feature is present in `TFeatures`, * then custom feature/plugin state is mixed in. */ -export type TableState = UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? TableState_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? TableState_ColumnGrouping - : never) - | ('columnOrderingFeature' extends keyof TFeatures - ? TableState_ColumnOrdering - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? TableState_ColumnPinning - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? TableState_ColumnResizing - : never) - | ('columnSizingFeature' extends keyof TFeatures - ? TableState_ColumnSizing - : never) - | ('columnVisibilityFeature' extends keyof TFeatures - ? TableState_ColumnVisibility - : never) - | ('globalFilteringFeature' extends keyof TFeatures - ? TableState_GlobalFiltering - : never) - | ('rowExpandingFeature' extends keyof TFeatures - ? TableState_RowExpanding - : never) - | ('rowPaginationFeature' extends keyof TFeatures - ? TableState_RowPagination - : never) - | ('rowPinningFeature' extends keyof TFeatures - ? TableState_RowPinning - : never) - | ('rowSelectionFeature' extends keyof TFeatures - ? TableState_RowSelection - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? TableState_RowSorting - : never) -> & - ExtractFeatureTypes<'TableState', TFeatures> & - TableState_Plugins - -// export type TableState = ExtractFeatureTypes< -// export type TableState = ExtractFeatureTypes< -// 'TableState', -// TFeatures -// > & -// TableState_Plugins +export type TableState = + ExtractFeatureMapTypes & + ExtractFeatureTypes<'TableState', TFeatures> & + TableState_Plugins /** * Internal broad state shape containing every stock feature state slice.