Skip to content

Commit

Permalink
reintroduce old uniontointersection types
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jan 7, 2025
1 parent e7bc229 commit 9af64a2
Show file tree
Hide file tree
Showing 36 changed files with 678 additions and 311 deletions.
6 changes: 3 additions & 3 deletions examples/react/grouping/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const tableHelper = createTableHelper({
rowSortingFeature,
},
_rowModels: {
expandedRowModel: createExpandedRowModel(),
filteredRowModel: createFilteredRowModel(filterFns),
groupedRowModel: createGroupedRowModel(aggregationFns),
paginatedRowModel: createPaginatedRowModel(),
sortedRowModel: createSortedRowModel(sortFns),
groupedRowModel: createGroupedRowModel(aggregationFns),
expandedRowModel: createExpandedRowModel(),
},
TData: [] as Array<Person>,
TData: {} as Person,
})

function App() {
Expand Down
13 changes: 5 additions & 8 deletions packages/angular-table/src/constructTableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import type { Signal } from '@angular/core'
* Options for creating a table helper to share common options across multiple tables
* coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions
*/
type TableHelperOptions<
export type TableHelperOptions<
TFeatures extends TableFeatures,
TDataList extends Array<RowData> = Array<any>,
> = Omit<
TableOptions<TFeatures, NoInfer<TDataList>>,
'columns' | 'data' | 'state'
> & {
TData extends RowData,
> = Omit<TableOptions<TFeatures, TData>, 'columns' | 'data' | 'state'> & {
_features: TFeatures
TData?: TDataList[number] // provide a cast for the TData type
TData?: TData // provide a cast for the TData type
}

/**
Expand Down Expand Up @@ -57,7 +54,7 @@ export function constructTableHelper<
tableCreator: (
tableOptions: () => TableOptions<TFeatures, TData>,
) => Table<TFeatures, TData> & Signal<Table<TFeatures, TData>>,
tableHelperOptions: TableHelperOptions<TFeatures, Array<TData>>,
tableHelperOptions: TableHelperOptions<TFeatures, TData>,
): TableHelper_Core<TFeatures, TData> {
const { TData: _TData, ..._tableHelperOptions } = tableHelperOptions
return {
Expand Down
6 changes: 4 additions & 2 deletions packages/angular-table/src/createTableHelper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { constructTableHelper } from './constructTableHelper'
import {
constructTableHelper,
TableHelperOptions,
} from './constructTableHelper'
import { injectTable } from './injectTable'
import type { Signal } from '@angular/core'
import type {
RowData,
Table,
TableFeatures,
TableHelperOptions,
TableHelper_Core,
TableOptions,
} from '@tanstack/table-core'
Expand Down
8 changes: 4 additions & 4 deletions packages/preact-table/src/createTableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export type TableHelper<

export function createTableHelper<
TFeatures extends TableFeatures,
TDataList extends Array<RowData> = Array<any>,
TData extends RowData,
>(
tableHelperOptions: TableHelperOptions<TFeatures, TDataList>,
): TableHelper<TFeatures, TDataList[number]> {
tableHelperOptions: TableHelperOptions<TFeatures, TData>,
): TableHelper<TFeatures, TData> {
const tableHelper = constructTableHelper(useTable, tableHelperOptions)
return {
...tableHelper,
useTable: tableHelper.tableCreator,
} as unknown as TableHelper<TFeatures, TDataList[number]>
} as unknown as TableHelper<TFeatures, TData>
}

// test
Expand Down
8 changes: 4 additions & 4 deletions packages/qwik-table/src/createTableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export type TableHelper<

export function createTableHelper<
TFeatures extends TableFeatures,
TDataList extends Array<RowData> = Array<any>,
TData extends RowData,
>(
tableHelperOptions: TableHelperOptions<TFeatures, TDataList>,
): TableHelper<TFeatures, TDataList[number]> {
tableHelperOptions: TableHelperOptions<TFeatures, TData>,
): TableHelper<TFeatures, TData> {
const tableHelper = constructTableHelper(useTable as any, tableHelperOptions)
return {
...tableHelper,
useTable: tableHelper.tableCreator,
} as unknown as TableHelper<TFeatures, TDataList[number]>
} as unknown as TableHelper<TFeatures, TData>
}

// test
Expand Down
8 changes: 4 additions & 4 deletions packages/react-table/src/createTableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export type TableHelper<

export function createTableHelper<
TFeatures extends TableFeatures,
TDataList extends Array<RowData> = Array<any>,
TData extends RowData,
>(
tableHelperOptions: TableHelperOptions<TFeatures, TDataList>,
): TableHelper<TFeatures, TDataList[number]> {
tableHelperOptions: TableHelperOptions<TFeatures, TData>,
): TableHelper<TFeatures, TData> {
const tableHelper = constructTableHelper(useTable, tableHelperOptions)
return {
...tableHelper,
useTable: tableHelper.tableCreator,
} as unknown as TableHelper<TFeatures, TDataList[number]>
} as unknown as TableHelper<TFeatures, TData>
}

// test
Expand Down
18 changes: 9 additions & 9 deletions packages/table-core/src/core/table/coreTablesFeature.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { CoreFeatures } from '../coreFeatures'
import type { RowModelFns } from '../../types/RowModelFns'
import type { NoInfer, RowData, Updater } from '../../types/type-utils'
import type { RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { CachedRowModels, CreateRowModels } from '../../types/RowModel'
import type { CachedRowModels, CreateRowModels_All } from '../../types/RowModel'
import type { TableOptions } from '../../types/TableOptions'
import type { TableState } from '../../types/TableState'

Expand All @@ -13,7 +13,7 @@ export interface TableMeta<

export interface TableOptions_Table<
TFeatures extends TableFeatures,
TDataList extends Array<RowData>,
TData extends RowData,
> {
/**
* The features that you want to enable for the table.
Expand All @@ -26,7 +26,7 @@ export interface TableOptions_Table<
* [API Docs](https://tanstack.com/table/v8/docs/api/core/table#_rowmodels)
* [Guide](https://tanstack.com/table/v8/docs/guide/tables)
*/
_rowModels?: CreateRowModels<TFeatures, NoInfer<TDataList[number]> | RowData>
_rowModels?: CreateRowModels_All<TFeatures, TData>
/**
* Set this option to override any of the `autoReset...` feature options.
* [API Docs](https://tanstack.com/table/v8/docs/api/core/table#autoresetall)
Expand All @@ -38,7 +38,7 @@ export interface TableOptions_Table<
* [API Docs](https://tanstack.com/table/v8/docs/api/core/table#data)
* [Guide](https://tanstack.com/table/v8/docs/guide/tables)
*/
data: TDataList
data: Array<TData>
/**
* Set this option to `true` to output all debugging information to the console.
* [API Docs](https://tanstack.com/table/v8/docs/api/core/table#debugall)
Expand Down Expand Up @@ -72,15 +72,15 @@ export interface TableOptions_Table<
* [Guide](https://tanstack.com/table/v8/docs/guide/tables)
*/
mergeOptions?: (
defaultOptions: TableOptions<TFeatures, TDataList[number]>,
options: Partial<TableOptions<TFeatures, TDataList[number]>>,
) => TableOptions<TFeatures, TDataList[number]>
defaultOptions: TableOptions<TFeatures, TData>,
options: Partial<TableOptions<TFeatures, TData>>,
) => TableOptions<TFeatures, TData>
/**
* You can pass any object to `options.meta` and access it anywhere the `table` is available via `table.options.meta`.
* [API Docs](https://tanstack.com/table/v8/docs/api/core/table#meta)
* [Guide](https://tanstack.com/table/v8/docs/guide/tables)
*/
meta?: TableMeta<TFeatures, TDataList[number]>
meta?: TableMeta<TFeatures, TData>
/**
* The `onStateChange` option can be used to optionally listen to state changes within the table.
* [API Docs](https://tanstack.com/table/v8/docs/api/core/table#onstatechange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import {
column_getFacetedRowModel,
column_getFacetedUniqueValues,
} from './columnFacetingFeature.utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type {
CachedRowModel_Faceted,
Column_ColumnFaceting,
CreateRowModel_Faceted,
} from './columnFacetingFeature.types'
import type { RowData } from '../../types/type-utils'
import type { TableFeature } from '../../types/TableFeatures'
// import type {
// CachedRowModel_Faceted,
// Column_ColumnFaceting,
// CreateRowModel_Faceted,
// } from './columnFacetingFeature.types'

interface ColumnFacetingFeatureConstructors {
Column: Column_ColumnFaceting<TableFeatures, RowData>
CreateRowModels: CreateRowModel_Faceted<TableFeatures, RowData>
CachedRowModel: CachedRowModel_Faceted<TableFeatures, RowData>
// Column: Column_ColumnFaceting<TableFeatures, RowData>
// CreateRowModels: CreateRowModel_Faceted<TableFeatures, RowData>
// CachedRowModel: CachedRowModel_Faceted<TableFeatures, RowData>
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,29 @@ import {
table_resetColumnFilters,
table_setColumnFilters,
} from './columnFilteringFeature.utils'
import type { RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type {
CachedRowModel_Filtered,
ColumnDef_ColumnFiltering,
Column_ColumnFiltering,
CreateRowModel_Filtered,
RowModelFns_ColumnFiltering,
Row_ColumnFiltering,
TableOptions_ColumnFiltering,
TableState_ColumnFiltering,
Table_ColumnFiltering,
} from './columnFilteringFeature.types'
import type { TableFeature } from '../../types/TableFeatures'
// import type {
// CachedRowModel_Filtered,
// ColumnDef_ColumnFiltering,
// Column_ColumnFiltering,
// CreateRowModel_Filtered,
// RowModelFns_ColumnFiltering,
// Row_ColumnFiltering,
// TableOptions_ColumnFiltering,
// TableState_ColumnFiltering,
// Table_ColumnFiltering,
// } from './columnFilteringFeature.types'

interface ColumnFilteringFeatureConstructors {
CachedRowModel: CachedRowModel_Filtered<TableFeatures, RowData>
Column: Column_ColumnFiltering<TableFeatures, RowData>
ColumnDef: ColumnDef_ColumnFiltering<TableFeatures, RowData>
CreateRowModels: CreateRowModel_Filtered<TableFeatures, RowData>
Row: Row_ColumnFiltering<TableFeatures, RowData>
RowModelFns: RowModelFns_ColumnFiltering<TableFeatures, RowData>
Table: Table_ColumnFiltering
TableOptions: TableOptions_ColumnFiltering<TableFeatures, RowData>
TableState: TableState_ColumnFiltering
// CachedRowModel: CachedRowModel_Filtered<TableFeatures, RowData>
// Column: Column_ColumnFiltering<TableFeatures, RowData>
// ColumnDef: ColumnDef_ColumnFiltering<TableFeatures, RowData>
// CreateRowModels: CreateRowModel_Filtered<TableFeatures, RowData>
// Row: Row_ColumnFiltering<TableFeatures, RowData>
// RowModelFns: RowModelFns_ColumnFiltering<TableFeatures, RowData>
// Table: Table_ColumnFiltering
// TableOptions: TableOptions_ColumnFiltering<TableFeatures, RowData>
// TableState: TableState_ColumnFiltering
}

/**
Expand Down Expand Up @@ -101,8 +100,8 @@ export const columnFilteringFeature: TableFeature<ColumnFilteringFeatureConstruc
},

constructRowAPIs: (row) => {
row.columnFilters = {}
row.columnFiltersMeta = {}
;(row as any).columnFilters = {}
;(row as any).columnFiltersMeta = {}
},

constructTableAPIs: (table) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,31 @@ import {
table_resetGrouping,
table_setGrouping,
} from './columnGroupingFeature.utils'
import type { RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type {
CachedRowModel_Grouped,
Cell_ColumnGrouping,
ColumnDef_ColumnGrouping,
Column_ColumnGrouping,
CreateRowModel_Grouped,
RowModelFns_ColumnGrouping,
Row_ColumnGrouping,
TableOptions_ColumnGrouping,
TableState_ColumnGrouping,
Table_ColumnGrouping,
} from './columnGroupingFeature.types'
import type { TableFeature } from '../../types/TableFeatures'
// import type {
// CachedRowModel_Grouped,
// Cell_ColumnGrouping,
// ColumnDef_ColumnGrouping,
// Column_ColumnGrouping,
// CreateRowModel_Grouped,
// RowModelFns_ColumnGrouping,
// Row_ColumnGrouping,
// TableOptions_ColumnGrouping,
// TableState_ColumnGrouping,
// Table_ColumnGrouping,
// } from './columnGroupingFeature.types'

interface ColumnGroupingFeatureConstructors {
CachedRowModel: CachedRowModel_Grouped<TableFeatures, RowData>
Cell: Cell_ColumnGrouping
Column: Column_ColumnGrouping<TableFeatures, RowData>
ColumnDef: ColumnDef_ColumnGrouping<TableFeatures, RowData>
CreateRowModels: CreateRowModel_Grouped<TableFeatures, RowData>
Row: Row_ColumnGrouping
RowModelFns: RowModelFns_ColumnGrouping<TableFeatures, RowData>
Table: Table_ColumnGrouping<TableFeatures, RowData>
TableOptions: TableOptions_ColumnGrouping
TableState: TableState_ColumnGrouping
// CachedRowModel: CachedRowModel_Grouped<TableFeatures, RowData>
// Cell: Cell_ColumnGrouping
// Column: Column_ColumnGrouping<TableFeatures, RowData>
// ColumnDef: ColumnDef_ColumnGrouping<TableFeatures, RowData>
// CreateRowModels: CreateRowModel_Grouped<TableFeatures, RowData>
// Row: Row_ColumnGrouping
// RowModelFns: RowModelFns_ColumnGrouping<TableFeatures, RowData>
// Table: Table_ColumnGrouping<TableFeatures, RowData>
// TableOptions: TableOptions_ColumnGrouping
// TableState: TableState_ColumnGrouping
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import {
table_resetColumnOrder,
table_setColumnOrder,
} from './columnOrderingFeature.utils'
import type { RowData } from '../../types/type-utils'
import type {
Column_ColumnOrdering,
TableOptions_ColumnOrdering,
TableState_ColumnOrdering,
Table_ColumnOrdering,
} from './columnOrderingFeature.types'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
// import type {
// Column_ColumnOrdering,
// TableOptions_ColumnOrdering,
// TableState_ColumnOrdering,
// Table_ColumnOrdering,
// } from './columnOrderingFeature.types'
import type { TableFeature } from '../../types/TableFeatures'

interface ColumnOrderingFeatureConstructors {
Column: Column_ColumnOrdering
Table: Table_ColumnOrdering<TableFeatures, RowData>
TableOptions: TableOptions_ColumnOrdering
TableState: TableState_ColumnOrdering
// Column: Column_ColumnOrdering
// Table: Table_ColumnOrdering<TableFeatures, RowData>
// TableOptions: TableOptions_ColumnOrdering
// TableState: TableState_ColumnOrdering
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@ import {
table_resetColumnPinning,
table_setColumnPinning,
} from './columnPinningFeature.utils'
import type { RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type {
ColumnDef_ColumnPinning,
Column_ColumnPinning,
Row_ColumnPinning,
TableOptions_ColumnPinning,
TableState_ColumnPinning,
Table_ColumnPinning,
} from './columnPinningFeature.types'
import type { TableFeature } from '../../types/TableFeatures'
// import type {
// ColumnDef_ColumnPinning,
// Column_ColumnPinning,
// Row_ColumnPinning,
// TableOptions_ColumnPinning,
// TableState_ColumnPinning,
// Table_ColumnPinning,
// } from './columnPinningFeature.types'

interface ColumnPinningFeatureConstructors {
Column: Column_ColumnPinning
ColumnDef: ColumnDef_ColumnPinning
Row: Row_ColumnPinning<TableFeatures, RowData>
Table: Table_ColumnPinning<TableFeatures, RowData>
TableOptions: TableOptions_ColumnPinning
TableState: TableState_ColumnPinning
// Column: Column_ColumnPinning
// ColumnDef: ColumnDef_ColumnPinning
// Row: Row_ColumnPinning<TableFeatures, RowData>
// Table: Table_ColumnPinning<TableFeatures, RowData>
// TableOptions: TableOptions_ColumnPinning
// TableState: TableState_ColumnPinning
}

/**
Expand Down
Loading

0 comments on commit 9af64a2

Please sign in to comment.