Skip to content

Commit 5088a85

Browse files
committed
Improve type safety of header/cell/footer fixed-data-table getters.
1 parent 2572eb9 commit 5088a85

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

fixed-data-table/fixed-data-table-tests.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference path="../react/react.d.ts"/>
33

44
import * as React from "react";
5-
import {Table, Cell, Column} from "fixed-data-table";
5+
import {Table, Cell, Column, CellProps} from "fixed-data-table";
66

77
// create your Table
88
class MyTable1 extends React.Component<{}, {}> {
@@ -68,7 +68,7 @@ class MyTable3 extends React.Component<{}, MyTable3State> {
6868
height={500}>
6969
<Column
7070
header={<Cell>Name</Cell>}
71-
cell={(props: any) => (
71+
cell={(props: CellProps) => (
7272
<Cell {...props}>
7373
{this.state.myTableData[props.rowIndex].name}
7474
</Cell>
@@ -85,7 +85,7 @@ interface RowData {
8585
[field: string]: string;
8686
}
8787

88-
interface MyCellProps {
88+
interface MyCellProps extends CellProps {
8989
rowIndex?: number;
9090
field: string;
9191
data: RowData[];

fixed-data-table/fixed-data-table.d.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,13 @@ declare module FixedDataTable {
284284
*
285285
* If you pass in a function, you will receive the same props object as the first argument.
286286
*/
287-
header?: any;
287+
header?: string | __React.ReactElement<any> | ((props: CellProps) => (string | __React.ReactElement<any>));
288288

289289
/**
290290
* This is the body cell that will be cloned for this
291291
* column. This can either be a string a React element,
292292
* or a function that generates a React Element. Passing
293-
* in a string will render a default header cell with that
293+
* in a string will render a default cell with that
294294
* string. By default, the React element passed in can
295295
* expect to receive the following props:
296296
*
@@ -308,7 +308,7 @@ declare module FixedDataTable {
308308
* If you pass in a function, you will receive the same
309309
* props object as the first argument.
310310
*/
311-
cell?: any;
311+
cell?: string | __React.ReactElement<any> | ((props: CellProps) => (string | __React.ReactElement<any>));
312312

313313
/**
314314
* The footer cell for this column. This can either be a
@@ -331,7 +331,7 @@ declare module FixedDataTable {
331331
* If you pass in a function, you will receive the same
332332
* props object as the first argument.
333333
*/
334-
footer?: any;
334+
footer?: string | __React.ReactElement<any> | ((props: CellProps) => (string | __React.ReactElement<any>));
335335

336336
/**
337337
* This is used to uniquely identify the column, and is not
@@ -433,7 +433,7 @@ declare module FixedDataTable {
433433
* If you pass in a function, you will receive the same props
434434
* object as the first argument.
435435
*/
436-
header: any;
436+
header: string | __React.ReactElement<any> | ((props: CellProps) => (string | __React.ReactElement<any>));
437437
}
438438

439439
/**
@@ -459,6 +459,11 @@ declare module FixedDataTable {
459459
* );
460460
*/
461461
export interface CellProps {
462+
/**
463+
* The row index of the cell.
464+
*/
465+
rowIndex?: number
466+
462467
/**
463468
* Outer height of the cell.
464469
*/
@@ -472,7 +477,7 @@ declare module FixedDataTable {
472477
/**
473478
* Optional prop that if specified on the Column will be
474479
* passed to the cell. It can be used to uniquely identify
475-
* which column is the cell is in.
480+
* which column is the cell is in.
476481
*/
477482
columnKey?: string | number;
478483
}

0 commit comments

Comments
 (0)