From 149fbf92cfe38c22b56e5c535d68d547ed12a37e Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sat, 20 Sep 2025 17:40:47 +0200 Subject: [PATCH] fix(table-core): CoreOptions columns and data are readonly --- docs/api/core/table.md | 4 ++-- packages/table-core/src/core/table.ts | 8 ++++---- packages/table-core/src/utils/getCoreRowModel.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/api/core/table.md b/docs/api/core/table.md index fbd1e06cf8..ee66910556 100644 --- a/docs/api/core/table.md +++ b/docs/api/core/table.md @@ -19,7 +19,7 @@ These are **core** options and API properties for the table. More options and AP ### `data` ```tsx -data: TData[] +data: readonly TData[] ``` The data for the table to display. This array should match the type you provided to `table.setRowType<...>`, but in theory could be an array of anything. It's common for each item in the array to be an object of key/values but this is not required. Columns can access this data via string/index or a functional accessor to return anything they want. @@ -31,7 +31,7 @@ When the `data` option changes reference (compared via `Object.is`), the table w ### `columns` ```tsx -type columns = ColumnDef[] +type columns = readonly ColumnDef[] ``` The array of column defs to use for the table. See the [Column Def Guide](../../../guide/column-defs.md) for more information on creating column definitions. diff --git a/packages/table-core/src/core/table.ts b/packages/table-core/src/core/table.ts index 00d62da98f..668d657493 100644 --- a/packages/table-core/src/core/table.ts +++ b/packages/table-core/src/core/table.ts @@ -78,13 +78,13 @@ export interface CoreOptions { * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#columns) * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) */ - columns: ColumnDef[] + columns: readonly ColumnDef[] /** * The data for the table to display. This array should match the type you provided to `table.setRowType<...>`. Columns can access this data via string/index or a functional accessor. When the `data` option changes reference, the table will reprocess the data. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#data) * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) */ - data: TData[] + data: readonly TData[] /** * Set this option to `true` to output all debugging information to the console. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#debugall) @@ -195,7 +195,7 @@ export interface CoreOptions { export interface CoreInstance { _features: readonly TableFeature[] _getAllFlatColumnsById: () => Record> - _getColumnDefs: () => ColumnDef[] + _getColumnDefs: () => readonly ColumnDef[] _getCoreRowModel?: () => RowModel _getDefaultColumnDef: () => Partial> _getRowId: (_: TData, index: number, parent?: Row) => string @@ -447,7 +447,7 @@ export function createTable( () => [table._getColumnDefs()], columnDefs => { const recurseColumns = ( - columnDefs: ColumnDef[], + columnDefs: readonly ColumnDef[], parent?: Column, depth = 0 ): Column[] => { diff --git a/packages/table-core/src/utils/getCoreRowModel.ts b/packages/table-core/src/utils/getCoreRowModel.ts index e6f7349a27..393283b6f8 100644 --- a/packages/table-core/src/utils/getCoreRowModel.ts +++ b/packages/table-core/src/utils/getCoreRowModel.ts @@ -22,7 +22,7 @@ export function getCoreRowModel(): ( } const accessRows = ( - originalRows: TData[], + originalRows: readonly TData[], depth = 0, parentRow?: Row ): Row[] => {