Skip to content

Commit c4f5b06

Browse files
[typescript] Improve type coverage of colDef (#2188)
* [typescript] Improve type coverage of colDef
1 parent 76b0a51 commit c4f5b06

22 files changed

+42
-23
lines changed

docs/pages/api-docs/data-grid/grid-cell-params.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GridCellParams } from '@material-ui/data-grid';
1616
| :------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- | :--------------------------------------------------------------- |
1717
| <span class="prop-name">api</span> | <span class="prop-type">any</span> | GridApi that let you manipulate the grid. |
1818
| <span class="prop-name">cellMode</span> | <span class="prop-type">GridCellMode</span> | The mode of the cell. |
19-
| <span class="prop-name">colDef</span> | <span class="prop-type">any</span> | The column of the row that the current cell belongs to. |
19+
| <span class="prop-name">colDef</span> | <span class="prop-type">GridStateColDef</span> | The column of the row that the current cell belongs to. |
2020
| <span class="prop-name">field</span> | <span class="prop-type">string</span> | The column field of the cell that triggered the event |
2121
| <span class="prop-name">formattedValue</span> | <span class="prop-type">GridCellValue</span> | The cell value formatted with the column valueFormatter. |
2222
| <span class="prop-name">getValue</span> | <span class="prop-type">(id: GridRowId, field: string) =&gt; GridCellValue</span> | Get the cell value of a row and field. |

docs/pages/api-docs/data-grid/grid-row-params.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { GridRowParams } from '@material-ui/data-grid';
1515
| Name | Type | Description |
1616
| :-------------------------------------- | :-------------------------------------------------------------------------------- | :--------------------------------------------------------- |
1717
| <span class="prop-name">api</span> | <span class="prop-type">any</span> | GridApiRef that let you manipulate the grid. |
18-
| <span class="prop-name">columns</span> | <span class="prop-type">any</span> | All grid columns. |
18+
| <span class="prop-name">columns</span> | <span class="prop-type">GridColumns</span> | All grid columns. |
1919
| <span class="prop-name">getValue</span> | <span class="prop-type">(id: GridRowId, field: string) =&gt; GridCellValue</span> | Get the cell value of a row and field. |
2020
| <span class="prop-name">id</span> | <span class="prop-type">GridRowId</span> | The grid row id. |
2121
| <span class="prop-name">row</span> | <span class="prop-type">GridRowData</span> | The row model of the row that the current cell belongs to. |

docs/scripts/formattedTSDemos.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ async function transpileFile(tsxPath, program, ignoreCache = false) {
8787

8888
const propTypesAST = typescriptToProptypes.parseFromProgram(tsxPath, program, {
8989
shouldResolveObject: ({ name }) => {
90-
if (name === 'classes' || name === 'state' || name === 'currentColumn') {
90+
if (
91+
name === 'classes' ||
92+
name === 'state' ||
93+
name === 'currentColumn' ||
94+
name === 'colDef'
95+
) {
9196
return false;
9297
}
9398

docs/src/pages/components/data-grid/columns/RenderExpandCellGrid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ renderCellExpand.propTypes = {
127127
/**
128128
* The column of the row that the current cell belongs to.
129129
*/
130-
colDef: PropTypes.any.isRequired,
130+
colDef: PropTypes.object.isRequired,
131131
/**
132132
* The cell value, but if the column has valueGetter, use getValue.
133133
*/

docs/src/pages/components/data-grid/sorting/ComparatorSortingGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const columns: GridColumns = [
2222
params.getValue(params.id, 'age') || 'x'
2323
}`,
2424
sortComparator: (v1, v2, param1, param2) =>
25-
param1.api.getCellValue(param1.id, 'age') -
26-
param2.api.getCellValue(param2.id, 'age'),
25+
(param1.api.getCellValue(param1.id, 'age') as number) -
26+
(param2.api.getCellValue(param2.id, 'age') as number),
2727
width: 150,
2828
},
2929
{ field: 'dateCreated', type: 'date', width: 180 },

docs/src/pages/components/data-grid/style/style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface GridRowParams {
4747
/**
4848
* All grid columns.
4949
*/
50-
columns: any;
50+
columns: GridColumns;
5151
/**
5252
* GridApiRef that let you manipulate the grid.
5353
*/

packages/grid/_modules_/grid/components/cell/GridBooleanCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const GridBooleanCell = React.memo((props: GridCellParams & SvgIconProps)
2020
} = props;
2121

2222
const Icon = React.useMemo(
23-
() => (value ? api.components.BooleanCellTrueIcon : api.components.BooleanCellFalseIcon),
23+
() => (value ? api.components.BooleanCellTrueIcon! : api.components.BooleanCellFalseIcon!),
2424
[api.components.BooleanCellFalseIcon, api.components.BooleanCellTrueIcon, value],
2525
);
2626

packages/grid/_modules_/grid/components/cell/GridEditSingleSelectCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function GridEditSingleSelectCell(props: GridCellParams & SelectProps) {
5858
open
5959
{...other}
6060
>
61-
{colDef.valueOptions.map(renderSingleSelectOptions)}
61+
{colDef.valueOptions?.map(renderSingleSelectOptions)}
6262
</Select>
6363
);
6464
}

packages/grid/_modules_/grid/components/columnHeaders/GridColumnHeaderItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
128128

129129
if (column.headerClassName) {
130130
const headerClassName = isFunction(column.headerClassName)
131-
? column.headerClassName({ field: column.field, colDef: column, api: apiRef })
131+
? column.headerClassName({ field: column.field, colDef: column, api: apiRef.current })
132132
: column.headerClassName;
133133

134134
classNames.push(headerClassName);

packages/grid/_modules_/grid/hooks/features/rows/useGridEditRows.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export function useGridEditRows(
115115

116116
const isCellEditable = React.useCallback(
117117
(params: GridCellParams) =>
118-
params.colDef.editable &&
119-
params.colDef!.renderEditCell &&
118+
!!params.colDef.editable &&
119+
!!params.colDef!.renderEditCell &&
120120
(!options.isCellEditable || options.isCellEditable(params)),
121121
// eslint-disable-next-line react-hooks/exhaustive-deps
122122
[options.isCellEditable],

0 commit comments

Comments
 (0)