fix: Table ts definition (#32358)

* fix: Table ts definition

* fix: backof default rowKey
This commit is contained in:
二货机器人 2021-09-30 11:43:42 +08:00 committed by GitHub
parent 8ec15224d3
commit ec9ecde052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -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';
@ -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',

View File

@ -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', () => {