Skip to content

Commit 178fb19

Browse files
authored
feat: add dataIndex type check (#1091)
* feat: add dataIndex type check * fix: ts * feat: add source * fix: ts * fix: ts * feat: 泛型默认值设置为 any * feat: add type test * feat: 优化 ddemo * feat: support empty string * feat: support empty string
1 parent 0c74710 commit 178fb19

36 files changed

+174
-84
lines changed

docs/examples/animation.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import CSSMotionList from 'rc-animate/lib/CSSMotionList';
33
import classNames from 'classnames';
44
import toArray from 'rc-util/lib/Children/toArray';
5+
import type { TableProps } from 'rc-table';
56
import Table from 'rc-table';
67
import '../../assets/index.less';
78
import './animation.less';
@@ -10,7 +11,7 @@ type MotionBodyProps = React.HTMLAttributes<HTMLTableSectionElement>;
1011

1112
const MotionBody: React.FC<MotionBodyProps> = ({ children, ...props }) => {
1213
const nodeList = toArray(children);
13-
const nodesRef = React.useRef<Record<React.Key, React.ReactElement>>({});
14+
const nodesRef = React.useRef<Record<string, React.ReactElement>>({});
1415

1516
// Better apply clean up logic to avoid OOM
1617
const keys: React.Key[] = [];
@@ -46,9 +47,9 @@ interface DemoState {
4647
}
4748

4849
class Demo extends React.Component<{}, DemoState> {
49-
columns = [
50+
columns: TableProps['columns'] = [
5051
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
51-
{ id: '123', title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
52+
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
5253
{ title: 'title3', dataIndex: 'c', key: 'c', width: 200 },
5354
{
5455
title: 'Operations',

docs/examples/aria.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import React from 'react';
2+
import type { TableProps } from 'rc-table';
23
import Table from 'rc-table';
34
import '../../assets/index.less';
45

5-
const columns = [
6+
interface FieldType {
7+
name?: string;
8+
age?: string;
9+
address?: string;
10+
}
11+
12+
const columns: TableProps<FieldType>['columns'] = [
613
{
714
title: 'Name',
815
dataIndex: 'name',

docs/examples/caption.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
2+
import type { TableProps } from 'rc-table';
23
import Table from 'rc-table';
34
import '../../assets/index.less';
45

5-
const columns = [
6+
const columns: TableProps['columns'] = [
67
{
78
title: 'Name',
89
dataIndex: 'name',

docs/examples/childrenIndent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { TableProps } from 'rc-table';
23
import Table from 'rc-table';
34
import '../../assets/index.less';
45

@@ -8,6 +9,7 @@ interface RecordType {
89
age: number;
910
address: string;
1011
children?: RecordType[];
12+
operation?: string;
1113
}
1214

1315
function CustomExpandIcon(props) {
@@ -27,7 +29,7 @@ function CustomExpandIcon(props) {
2729
);
2830
}
2931

30-
const columns = [
32+
const columns: TableProps<RecordType>['columns'] = [
3133
{
3234
title: 'Name',
3335
dataIndex: 'name',

docs/examples/className.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
2+
import type { TableProps } from 'rc-table';
23
import Table from 'rc-table';
34
import '../../assets/index.less';
45

5-
const columns = [
6+
const columns: TableProps['columns'] = [
67
{
78
title: 'title1',
89
dataIndex: 'a',
@@ -11,7 +12,6 @@ const columns = [
1112
width: 100,
1213
},
1314
{
14-
id: '123',
1515
title: 'title2',
1616
dataIndex: 'b',
1717
className: 'b',

docs/examples/colspan-rowspan-legacy.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import Table from 'rc-table';
33
import '../../assets/index.less';
4-
import { ColumnsType, RenderedCell } from '@/interface';
4+
import type { ColumnsType, RenderedCell } from '@/interface';
55

66
interface RecordType {
77
a?: string;
@@ -116,7 +116,6 @@ const columns: ColumnsType<RecordType> = [
116116
},
117117
{
118118
title: 'Operations',
119-
dataIndex: '',
120119
key: 'f',
121120
render(o, row, index) {
122121
if (index === 5) {

docs/examples/colspan-rowspan.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ const columns: ColumnsType<RecordType> = [
9797
},
9898
{
9999
title: 'Operations',
100-
dataIndex: '',
101100
key: 'f',
102101
render() {
103102
return <a href="#">Operations</a>;

docs/examples/column-resize.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Resizable } from 'react-resizable';
33
import Table from 'rc-table';
44
import '../../assets/index.less';
55
import 'react-resizable/css/styles.css';
6-
import { ColumnType } from '@/interface';
6+
import type { ColumnType } from '@/interface';
77

88
const ResizableTitle = props => {
99
const { onResize, width, ...restProps } = props;
@@ -31,7 +31,6 @@ interface DemoState {
3131
columns: ColumnType<RecordType>[];
3232
}
3333

34-
3534
class Demo extends React.Component<{}, DemoState> {
3635
state: DemoState = {
3736
columns: [
@@ -61,16 +60,18 @@ class Demo extends React.Component<{}, DemoState> {
6160
{ a: '1333', c: 'eee', d: 2, key: '3' },
6261
];
6362

64-
handleResize = index => (e, { size }) => {
65-
this.setState(({ columns }) => {
66-
const nextColumns = [...columns];
67-
nextColumns[index] = {
68-
...nextColumns[index],
69-
width: size.width,
70-
};
71-
return { columns: nextColumns };
72-
});
73-
};
63+
handleResize =
64+
index =>
65+
(e, { size }) => {
66+
this.setState(({ columns }) => {
67+
const nextColumns = [...columns];
68+
nextColumns[index] = {
69+
...nextColumns[index],
70+
width: size.width,
71+
};
72+
return { columns: nextColumns };
73+
});
74+
};
7475

7576
render() {
7677
const columns = this.state.columns.map((col, index) => ({
@@ -79,7 +80,7 @@ class Demo extends React.Component<{}, DemoState> {
7980
({
8081
width: column.width,
8182
onResize: this.handleResize(index),
82-
} as any),
83+
}) as any,
8384
}));
8485

8586
return (

docs/examples/ellipsis-custom-tooltip.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import Tooltip from 'rc-tooltip';
3+
import type { TableProps } from 'rc-table';
34
import Table from 'rc-table';
45
import '../../assets/index.less';
56
import 'rc-tooltip/assets/bootstrap.css';
@@ -23,7 +24,7 @@ const createColumns = (length: number) => {
2324
}));
2425
};
2526

26-
const columns = [
27+
const columns: TableProps['columns'] = [
2728
{
2829
title: 'name',
2930
dataIndex: 'name',

docs/examples/ellipsis.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
2+
import type { TableProps } from 'rc-table';
23
import Table from 'rc-table';
34
import '../../assets/index.less';
45

5-
const columns = [
6+
const columns: TableProps['columns'] = [
67
{ title: 'name', dataIndex: 'name', width: 100, ellipsis: true },
78
{ title: 'descrption', dataIndex: 'descrption', key: 'descrption 1', ellipsis: true, width: 50 },
89
{ title: 'descrption', dataIndex: 'descrption', key: 'descrption 2', ellipsis: true },

0 commit comments

Comments
 (0)