Skip to content

Commit 1f8db0b

Browse files
committed
Added 41
1 parent 3d1b4ca commit 1f8db0b

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { ReactNode } from "react";
2+
import { Equal, Expect } from "../helpers/type-utils";
3+
4+
interface TableProps<T> {
5+
rows: T[];
6+
renderRow: (row: T) => ReactNode;
7+
}
8+
9+
export const Table = <T,>(props: TableProps<T>) => {
10+
return (
11+
<table>
12+
<tbody>
13+
{props.rows.map((row) => (
14+
<tr>{props.renderRow(row)}</tr>
15+
))}
16+
</tbody>
17+
</table>
18+
);
19+
};
20+
21+
interface User {
22+
id: number;
23+
name: string;
24+
age: number;
25+
}
26+
27+
<>
28+
<Table
29+
// @ts-expect-error rows should be User[]
30+
rows={[1, 2, 3]}
31+
renderRow={(row) => {
32+
type test = Expect<Equal<typeof row, User>>;
33+
return <td>{row.name}</td>;
34+
}}
35+
/>
36+
<Table
37+
rows={[
38+
{
39+
id: 1,
40+
name: "John",
41+
age: 30,
42+
},
43+
{
44+
// @ts-expect-error id should be string
45+
id: "2",
46+
name: "Jane",
47+
age: 30,
48+
},
49+
]}
50+
renderRow={(row) => {
51+
type test = Expect<Equal<typeof row, User>>;
52+
return <td>{row.name}</td>;
53+
}}
54+
></Table>
55+
</>;

0 commit comments

Comments
 (0)