Skip to content

Commit 5af9ea3

Browse files
committed
Make column renderer use the same type as its key
That way the renderer only takes `string` for example when rendering the name field instead of `string | number` when the interface has some fields that are strings and some fields are numbers. This will be necessary when switching to generated types since some of the fields are numbers (like the owner count on a template).
1 parent 10bb649 commit 5af9ea3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

site/src/components/Table/Table.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import React from "react"
88
import { TableHeaders } from "../TableHeaders/TableHeaders"
99
import { TableTitle } from "../TableTitle/TableTitle"
1010

11-
export interface Column<T> {
11+
export type Column<T> = { [K in keyof T]: {
1212
/**
1313
* The field of type T that this column is associated with
1414
*/
15-
key: keyof T
15+
key: K
1616
/**
1717
* Friendly name of the field, shown in headers
1818
*/
1919
name: string
2020
/**
2121
* Custom render for the field inside the table
2222
*/
23-
renderer?: (field: T[keyof T], data: T) => React.ReactElement
24-
}
23+
renderer?: (field: T[K], data: T) => React.ReactElement
24+
} }[keyof T]
2525

2626
export interface TableProps<T> {
2727
/**

0 commit comments

Comments
 (0)