Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 8350c64

Browse files
author
Marc-André Rivet
committed
Improving typing on data prop and related manipulations
1 parent e3d6fca commit 8350c64

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/dash-table/components/Table/derivedPropsHelper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import QuerySyntaxTree from 'dash-table/syntax-tree/QuerySyntaxTree';
66

77
import {
88
ControlledTableProps,
9+
IndexedData,
910
SanitizedAndDerivedProps,
1011
SetProps,
1112
TableAction
@@ -67,19 +68,19 @@ export default () => {
6768
if (!virtualCached) {
6869
newProps.derived_virtual_data = virtual.data;
6970
newProps.derived_virtual_indices = virtual.indices;
70-
newProps.derived_virtual_row_ids = R.pluck('id', virtual.data);
71+
newProps.derived_virtual_row_ids = R.pluck('id', virtual.data as IndexedData);
7172
}
7273

7374
if (!viewportCached) {
7475
newProps.derived_viewport_data = viewport.data;
7576
newProps.derived_viewport_indices = viewport.indices;
76-
newProps.derived_viewport_row_ids = R.pluck('id', viewport.data);
77+
newProps.derived_viewport_row_ids = R.pluck('id', viewport.data as IndexedData);
7778
}
7879

7980
if (!virtualSelectedRowsCached) {
8081
newProps.derived_virtual_selected_rows = virtual_selected_rows;
8182
newProps.derived_virtual_selected_row_ids = R.map(
82-
i => virtual.data[i].id,
83+
i => (virtual.data as IndexedData)[i].id,
8384
virtual_selected_rows
8485
);
8586
}
@@ -91,7 +92,7 @@ export default () => {
9192
if (!viewportSelectedRowsCached) {
9293
newProps.derived_viewport_selected_rows = viewport_selected_rows;
9394
newProps.derived_viewport_selected_row_ids = R.map(
94-
i => viewport.data[i].id,
95+
i => (viewport.data as IndexedData)[i].id,
9596
viewport_selected_rows
9697
);
9798
}

src/dash-table/components/Table/props.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export interface ICellCoordinates {
8484
export type ColumnId = string;
8585
export type Columns = IColumn[];
8686
export type Data = Datum[];
87+
export type IndexedData = IndexedDatum[];
8788
export type Datum = IDatumObject;
89+
export type IndexedDatum = Omit<Datum, 'id'> & { id: number | string; };
8890
export type Indices = number[];
8991
export type RowId = string | number;
9092
export type SelectedCells = ICellCoordinates[];
@@ -199,7 +201,7 @@ export type IColumnType = INumberColumn | ITextColumn | IDatetimeColumn | IAnyCo
199201
export type IColumn = IBaseColumn & IColumnType;
200202

201203
interface IDatumObject {
202-
[key: string]: any;
204+
[key: string]: boolean | number | string | null | undefined;
203205
}
204206

205207
export interface IDropdownValue {

src/dash-table/derived/cell/cellProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { map, range, xprod } from 'ramda';
2-
import { ICellCoordinates, Columns, IDerivedData } from 'dash-table/components/Table/props';
2+
import { ICellCoordinates, Columns, IDerivedData, IndexedData } from 'dash-table/components/Table/props';
33

44
export function makeCell (
55
row: number,
@@ -12,7 +12,7 @@ export function makeCell (
1212
column,
1313
column_id: columns[column].id
1414
};
15-
const rowId = viewport.data[row].id;
15+
const rowId = (viewport.data as IndexedData)[row].id;
1616
if (rowId !== undefined) {
1717
cell.row_id = rowId;
1818
}

0 commit comments

Comments
 (0)