WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 149fbf9

Browse files
committed
fix(table-core): CoreOptions columns and data are readonly
1 parent 569a6e8 commit 149fbf9

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

docs/api/core/table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ These are **core** options and API properties for the table. More options and AP
1919
### `data`
2020
2121
```tsx
22-
data: TData[]
22+
data: readonly TData[]
2323
```
2424
2525
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
3131
### `columns`
3232
3333
```tsx
34-
type columns = ColumnDef<TData>[]
34+
type columns = readonly ColumnDef<TData>[]
3535
```
3636
3737
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.

packages/table-core/src/core/table.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ export interface CoreOptions<TData extends RowData> {
7878
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#columns)
7979
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
8080
*/
81-
columns: ColumnDef<TData, any>[]
81+
columns: readonly ColumnDef<TData, any>[]
8282
/**
8383
* 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.
8484
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#data)
8585
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
8686
*/
87-
data: TData[]
87+
data: readonly TData[]
8888
/**
8989
* Set this option to `true` to output all debugging information to the console.
9090
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#debugall)
@@ -195,7 +195,7 @@ export interface CoreOptions<TData extends RowData> {
195195
export interface CoreInstance<TData extends RowData> {
196196
_features: readonly TableFeature[]
197197
_getAllFlatColumnsById: () => Record<string, Column<TData, unknown>>
198-
_getColumnDefs: () => ColumnDef<TData, unknown>[]
198+
_getColumnDefs: () => readonly ColumnDef<TData, unknown>[]
199199
_getCoreRowModel?: () => RowModel<TData>
200200
_getDefaultColumnDef: () => Partial<ColumnDef<TData, unknown>>
201201
_getRowId: (_: TData, index: number, parent?: Row<TData>) => string
@@ -447,7 +447,7 @@ export function createTable<TData extends RowData>(
447447
() => [table._getColumnDefs()],
448448
columnDefs => {
449449
const recurseColumns = (
450-
columnDefs: ColumnDef<TData, unknown>[],
450+
columnDefs: readonly ColumnDef<TData, unknown>[],
451451
parent?: Column<TData, unknown>,
452452
depth = 0
453453
): Column<TData, unknown>[] => {

packages/table-core/src/utils/getCoreRowModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function getCoreRowModel<TData extends RowData>(): (
2222
}
2323

2424
const accessRows = (
25-
originalRows: TData[],
25+
originalRows: readonly TData[],
2626
depth = 0,
2727
parentRow?: Row<TData>
2828
): Row<TData>[] => {

0 commit comments

Comments
 (0)