Skip to content

Commit

Permalink
fix: Table ts define (#20695)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jan 6, 2020
1 parent 7d95365 commit 6017b3f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
17 changes: 17 additions & 0 deletions components/table/Column.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ColumnType } from './interface';

export interface ColumnProps<RecordType> extends ColumnType<RecordType> {
children?: null;
}

/* istanbul ignore next */
/**
* This is a syntactic sugar for `columns` prop.
* So HOC will not work on this.
*/
// eslint-disable-next-line no-unused-vars
function Column<RecordType>(_: ColumnProps<RecordType>) {
return null;
}

export default Column;
20 changes: 20 additions & 0 deletions components/table/ColumnGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ColumnType } from './interface';
import { ColumnProps } from './Column';

export interface ColumnGroupProps<RecordType> extends Omit<ColumnType<RecordType>, 'children'> {
children:
| React.ReactElement<ColumnProps<RecordType>>
| React.ReactElement<ColumnProps<RecordType>>[];
}

/* istanbul ignore next */
/**
* This is a syntactic sugar for `columns` prop.
* So HOC will not work on this.
*/
// eslint-disable-next-line no-unused-vars
function ColumnGroup<RecordType>(_: ColumnGroupProps<RecordType>) {
return null;
}

export default ColumnGroup;
4 changes: 3 additions & 1 deletion components/table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import RcTable, { Column, ColumnGroup } from 'rc-table';
import RcTable from 'rc-table';
import { TableProps as RcTableProps, INTERNAL_HOOKS } from 'rc-table/lib/Table';
import Spin, { SpinProps } from '../spin';
import Pagination, { PaginationConfig } from '../pagination';
Expand Down Expand Up @@ -29,6 +29,8 @@ import renderExpandIcon from './ExpandIcon';
import scrollTo from '../_util/scrollTo';
import defaultLocale from '../locale/en_US';
import SizeContext, { SizeType } from '../config-provider/SizeContext';
import Column from './Column';
import ColumnGroup from './ColumnGroup';

export { ColumnsType, TablePaginationConfig };

Expand Down
24 changes: 24 additions & 0 deletions components/table/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable no-unused-expressions */

import * as React from 'react';
import Table from '../Table';

const { Column, ColumnGroup } = Table;

describe('Table.typescript', () => {
it('Column', () => {
<Table>
<Column dataIndex="test" title="test" sorter />
</Table>;
});
it('ColumnGroup', () => {
<Table>
<Column dataIndex="test" title="test" sorter />
<ColumnGroup>
<Column dataIndex="test" title="test" sorter />
</ColumnGroup>
</Table>;
});
});

/* eslint-enable */

0 comments on commit 6017b3f

Please sign in to comment.