diff --git a/packages/table-core/src/core/cell.ts b/packages/table-core/src/core/cell.ts index 2638e9e6f7..c52a54b75e 100644 --- a/packages/table-core/src/core/cell.ts +++ b/packages/table-core/src/core/cell.ts @@ -1,7 +1,7 @@ import { RowData, Cell, Column, Row, Table } from '../types' import { Getter, getMemoOptions, memo } from '../utils' -export interface CellContext { +export interface CellContext { cell: Cell column: Column getValue: Getter @@ -10,7 +10,7 @@ export interface CellContext { table: Table } -export interface CoreCell { +export interface CoreCell { /** * The associated Column object for the cell. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/cell#column) diff --git a/packages/table-core/src/core/column.ts b/packages/table-core/src/core/column.ts index cbc220b724..500c90d26c 100644 --- a/packages/table-core/src/core/column.ts +++ b/packages/table-core/src/core/column.ts @@ -8,7 +8,7 @@ import { } from '../types' import { getMemoOptions, memo } from '../utils' -export interface CoreColumn { +export interface CoreColumn { /** * The resolved accessor function to use when extracting the value for the column from each row. Will only be defined if the column def has a valid accessor key or function defined. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/column#accessorfn) diff --git a/packages/table-core/src/core/headers.ts b/packages/table-core/src/core/headers.ts index 70b9167635..5851762518 100644 --- a/packages/table-core/src/core/headers.ts +++ b/packages/table-core/src/core/headers.ts @@ -16,7 +16,7 @@ export interface CoreHeaderGroup { id: string } -export interface HeaderContext { +export interface HeaderContext { /** * An instance of a column. */ @@ -31,7 +31,7 @@ export interface HeaderContext { table: Table } -export interface CoreHeader { +export interface CoreHeader { /** * The col-span for the header. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#colspan) diff --git a/packages/table-core/src/features/ColumnFaceting.ts b/packages/table-core/src/features/ColumnFaceting.ts index f356252deb..df65a11f48 100644 --- a/packages/table-core/src/features/ColumnFaceting.ts +++ b/packages/table-core/src/features/ColumnFaceting.ts @@ -46,8 +46,8 @@ export interface FacetedOptions { // export const ColumnFaceting: TableFeature = { - createColumn: ( - column: Column, + createColumn: ( + column: Column, table: Table, ): void => { column._getFacetedRowModel = diff --git a/packages/table-core/src/features/ColumnFiltering.ts b/packages/table-core/src/features/ColumnFiltering.ts index 77b9927c04..8989058f5f 100644 --- a/packages/table-core/src/features/ColumnFiltering.ts +++ b/packages/table-core/src/features/ColumnFiltering.ts @@ -265,8 +265,8 @@ export const ColumnFiltering: TableFeature = { } as ColumnFiltersOptions }, - createColumn: ( - column: Column, + createColumn: ( + column: Column, table: Table, ): void => { column.getAutoFilterFn = () => { @@ -334,7 +334,7 @@ export const ColumnFiltering: TableFeature = { // if ( - shouldAutoRemoveFilter(filterFn as FilterFn, newFilter, column) + shouldAutoRemoveFilter(filterFn as FilterFn, newFilter, column as Column) ) { return old?.filter((d) => d.id !== column.id) ?? [] } diff --git a/packages/table-core/src/features/ColumnGrouping.ts b/packages/table-core/src/features/ColumnGrouping.ts index 58b9fa082b..b693478e26 100644 --- a/packages/table-core/src/features/ColumnGrouping.ts +++ b/packages/table-core/src/features/ColumnGrouping.ts @@ -34,7 +34,7 @@ export type AggregationFnOption = | BuiltInAggregationFn | AggregationFn -export interface GroupingColumnDef { +export interface GroupingColumnDef { /** * The cell to display each row for the column if the cell is an aggregate. If a function is passed, it will be passed a props object with the context of the cell and should return the property type for your adapter (the exact type depends on the adapter being used). * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#aggregatedcell) diff --git a/packages/table-core/src/features/ColumnOrdering.ts b/packages/table-core/src/features/ColumnOrdering.ts index cd4fc9626d..dea215221a 100644 --- a/packages/table-core/src/features/ColumnOrdering.ts +++ b/packages/table-core/src/features/ColumnOrdering.ts @@ -88,8 +88,8 @@ export const ColumnOrdering: TableFeature = { } }, - createColumn: ( - column: Column, + createColumn: ( + column: Column, table: Table, ): void => { column.getIndex = memo( diff --git a/packages/table-core/src/features/GlobalFiltering.ts b/packages/table-core/src/features/GlobalFiltering.ts index 6ec384ece4..6da7a13064 100644 --- a/packages/table-core/src/features/GlobalFiltering.ts +++ b/packages/table-core/src/features/GlobalFiltering.ts @@ -118,8 +118,8 @@ export const GlobalFiltering: TableFeature = { } as GlobalFilterOptions }, - createColumn: ( - column: Column, + createColumn: ( + column: Column, table: Table, ): void => { column.getCanGlobalFilter = () => { @@ -127,7 +127,7 @@ export const GlobalFiltering: TableFeature = { (column.columnDef.enableGlobalFilter ?? true) && (table.options.enableGlobalFilter ?? true) && (table.options.enableFilters ?? true) && - (table.options.getColumnCanGlobalFilter?.(column) ?? true) && + (table.options.getColumnCanGlobalFilter?.(column as Column) ?? true) && !!column.accessorFn ) } diff --git a/packages/table-core/src/types.ts b/packages/table-core/src/types.ts index ba933e4592..c4729f98df 100644 --- a/packages/table-core/src/types.ts +++ b/packages/table-core/src/types.ts @@ -98,14 +98,20 @@ import { CellContext, CoreCell } from './core/cell' import { CoreColumn } from './core/column' export interface TableFeature { - createCell?: ( - cell: Cell, - column: Column, + createCell?: ( + cell: Cell, + column: Column, row: Row, table: Table, ) => void - createColumn?: (column: Column, table: Table) => void - createHeader?: (header: Header, table: Table) => void + createColumn?: ( + column: Column, + table: Table + ) => void + createHeader?: ( + header: Header, + table: Table + ) => void createRow?: (row: Row, table: Table) => void createTable?: (table: Table) => void getDefaultColumnDef?: () => Partial> @@ -227,7 +233,7 @@ export interface RowModel { rowsById: Record> } -export type AccessorFn = ( +export type AccessorFn = ( originalRow: TData, index: number, ) => TValue @@ -256,7 +262,7 @@ type ColumnIdentifiers = // -interface ColumnDefExtensions +interface ColumnDefExtensions extends VisibilityColumnDef, ColumnPinningColumnDef, @@ -267,8 +273,8 @@ interface ColumnDefExtensions ColumnSizingColumnDef {} export interface ColumnDefBase< - TData extends RowData, - TValue = unknown, + in out TData extends RowData, + in out TValue = unknown, > extends ColumnDefExtensions { getUniqueValues?: AccessorFn footer?: ColumnDefTemplate> @@ -279,8 +285,8 @@ export interface ColumnDefBase< // export interface IdentifiedColumnDef< - TData extends RowData, - TValue = unknown, + in out TData extends RowData, + in out TValue = unknown, > extends ColumnDefBase { id?: string header?: StringOrTemplateHeader @@ -292,8 +298,8 @@ export type DisplayColumnDef< > = ColumnDefBase & ColumnIdentifiers interface GroupColumnDefBase< - TData extends RowData, - TValue = unknown, + in out TData extends RowData, + in out TValue = unknown, > extends ColumnDefBase { columns?: ColumnDef[] } @@ -304,8 +310,8 @@ export type GroupColumnDef< > = GroupColumnDefBase & ColumnIdentifiers export interface AccessorFnColumnDefBase< - TData extends RowData, - TValue = unknown, + in out TData extends RowData, + in out TValue = unknown, > extends ColumnDefBase { accessorFn: AccessorFn } @@ -316,8 +322,8 @@ export type AccessorFnColumnDef< > = AccessorFnColumnDefBase & ColumnIdentifiers export interface AccessorKeyColumnDefBase< - TData extends RowData, - TValue = unknown, + in out TData extends RowData, + in out TValue = unknown, > extends ColumnDefBase { id?: string accessorKey: (string & {}) | keyof TData @@ -347,7 +353,7 @@ export type ColumnDefResolved< accessorKey?: string } -export interface Column +export interface Column extends CoreColumn, ColumnVisibilityColumn, @@ -360,11 +366,13 @@ export interface Column ColumnSizingColumn, ColumnOrderColumn {} -export interface Cell - extends CoreCell, GroupingCell {} +export interface Cell + extends CoreCell, + GroupingCell {} -export interface Header - extends CoreHeader, ColumnSizingHeader {} +export interface Header + extends CoreHeader, + ColumnSizingHeader {} export interface HeaderGroup< TData extends RowData,