Skip to content

Commit d5eb87f

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 d5eb87f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

site/src/components/Table/Table.tsx

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

11-
export interface Column<T> {
12-
/**
13-
* The field of type T that this column is associated with
14-
*/
15-
key: keyof T
16-
/**
17-
* Friendly name of the field, shown in headers
18-
*/
19-
name: string
20-
/**
21-
* Custom render for the field inside the table
22-
*/
23-
renderer?: (field: T[keyof T], data: T) => React.ReactElement
24-
}
11+
export type Column<T> = {
12+
[K in keyof T]: {
13+
/**
14+
* The field of type T that this column is associated with
15+
*/
16+
key: K
17+
/**
18+
* Friendly name of the field, shown in headers
19+
*/
20+
name: string
21+
/**
22+
* Custom render for the field inside the table
23+
*/
24+
renderer?: (field: T[K], data: T) => React.ReactElement
25+
}
26+
}[keyof T]
2527

2628
export interface TableProps<T> {
2729
/**

0 commit comments

Comments
 (0)