Skip to content

Commit 5d59563

Browse files
authored
Annotate Grid and List return types explicitly to avoid redundant inlined inferred types (#876)
1 parent b2fe9ed commit 5d59563

File tree

7 files changed

+18
-6
lines changed

7 files changed

+18
-6
lines changed

lib/components/grid/Grid.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe("Grid", () => {
168168
/>
169169
);
170170

171-
const NewCellComponent = vi.fn(() => null);
171+
const NewCellComponent = vi.fn(() => <div />);
172172

173173
rerender(
174174
<Grid

lib/components/grid/Grid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useImperativeHandle,
66
useMemo,
77
useState,
8+
type ReactElement,
89
type ReactNode
910
} from "react";
1011
import { useIsRtl } from "../../core/useIsRtl";
@@ -36,7 +37,7 @@ export function Grid<
3637
style,
3738
tagName = "div" as TagName,
3839
...rest
39-
}: GridProps<CellProps, TagName>) {
40+
}: GridProps<CellProps, TagName>): ReactElement {
4041
const cellProps = useMemoizedObject(cellPropsUnstable);
4142
const CellComponent = useMemo(
4243
() => memo(CellComponentProp, arePropsEqual),

lib/components/grid/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
ComponentProps,
33
CSSProperties,
44
HTMLAttributes,
5+
ReactElement,
56
ReactNode,
67
Ref
78
} from "react";
@@ -34,7 +35,7 @@ export type GridProps<
3435
rowIndex: number;
3536
style: CSSProperties;
3637
} & CellProps
37-
) => ReactNode;
38+
) => ReactElement;
3839

3940
/**
4041
* Additional props to be passed to the cell-rendering component.

lib/components/list/List.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe("List", () => {
181181
/>
182182
);
183183

184-
const NewRowComponent = vi.fn(() => null);
184+
const NewRowComponent = vi.fn(() => <div />);
185185

186186
rerender(
187187
<List

lib/components/list/List.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useImperativeHandle,
66
useMemo,
77
useState,
8+
type ReactElement,
89
type ReactNode
910
} from "react";
1011
import { useVirtualizer } from "../../core/useVirtualizer";
@@ -35,7 +36,7 @@ export function List<
3536
tagName = "div" as TagName,
3637
style,
3738
...rest
38-
}: ListProps<RowProps, TagName>) {
39+
}: ListProps<RowProps, TagName>): ReactElement {
3940
const rowProps = useMemoizedObject(rowPropsUnstable);
4041
const RowComponent = useMemo(
4142
() => memo(RowComponentProp, arePropsEqual),

lib/components/list/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
ComponentProps,
33
CSSProperties,
44
HTMLAttributes,
5+
ReactElement,
56
ReactNode,
67
Ref
78
} from "react";
@@ -98,7 +99,7 @@ export type ListProps<
9899
index: number;
99100
style: CSSProperties;
100101
} & RowProps
101-
) => ReactNode;
102+
) => ReactElement;
102103

103104
/**
104105
* Number of items to be rendered in the list.

scripts/utils/getPropTypeText.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ export function getPropTypeText(prop: PropItem) {
55
if (!textToFormat && prop.type.name.includes(":")) {
66
// Edge case where some prop types aren't registered as containing raw TS
77
textToFormat = prop.type.name;
8+
9+
// List/Grid and rowComponent/cellComponent are annotated with a return type of ReactElement instead of ReactNode
10+
// As a result of this change the generated docs are significantly less readable, so tidy them up here
11+
// See github.com/bvaughn/react-window/issues/875
12+
textToFormat = textToFormat.replace(
13+
"ReactElement<unknown, string | JSXElementConstructor<...>>",
14+
"ReactNode"
15+
);
816
}
917

1018
if (!textToFormat) {

0 commit comments

Comments
 (0)