Skip to content

Commit

Permalink
fix: Table ts definition (ant-design#32358)
Browse files Browse the repository at this point in the history
* fix: Table ts definition

* fix: backof default rowKey
  • Loading branch information
zombieJ authored Sep 30, 2021
1 parent 8ec1522 commit ec9ecde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,14 @@ function InternalTable<RecordType extends object = any>(
);
}

const TableRef = React.forwardRef(InternalTable);
const ForwardTable = React.forwardRef(InternalTable) as <RecordType extends object = any>(
props: React.PropsWithChildren<TableProps<RecordType>> & { ref?: React.Ref<HTMLDivElement> },
) => React.ReactElement;

type InternalTableType = typeof TableRef;
type InternalTableType = typeof ForwardTable;

interface TableInterface extends InternalTableType {
defaultProps?: Partial<TableProps<any>>;
SELECTION_ALL: 'SELECT_ALL';
SELECTION_INVERT: 'SELECT_INVERT';
SELECTION_NONE: 'SELECT_NONE';
Expand All @@ -529,7 +532,7 @@ interface TableInterface extends InternalTableType {
Summary: typeof Summary;
}

const Table = TableRef as TableInterface;
const Table = ForwardTable as TableInterface;

Table.defaultProps = {
rowKey: 'key',
Expand Down
8 changes: 8 additions & 0 deletions components/table/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe('Table.typescript', () => {
const table = <Table rowSelection={{ selections: [Table.SELECTION_ALL] }} />;
expect(table).toBeTruthy();
});

it('generic', () => {
interface RecordType {
key: string;
}
const table = <Table<RecordType> dataSource={[{ key: 'Bamboo' }]} />;
expect(table).toBeTruthy();
});
});

describe('Table.typescript types', () => {
Expand Down

0 comments on commit ec9ecde

Please sign in to comment.