From 937beba4217f9d3152c72a24fa1fb34d56a723d7 Mon Sep 17 00:00:00 2001 From: xiaoxintang <15707971810@163.com> Date: Wed, 22 Apr 2020 21:59:18 +0800 Subject: [PATCH] fix: Table selections type when use Table.SELECTION_ALL or Table.SELECTION_INVERT (#23462) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:selections type when use SELECTION_ALL | SELECTION_INVERT * fix: Table selections type when use Table.SELECTION_ALL or Table.SELECTION_INVERT * fix: Table selections type when use Table.SELECTION_ALL or Table.SELECTION_INVERT * Update useSelection.tsx * Update type.test.tsx Co-authored-by: 二货机器人 --- components/table/__tests__/type.test.tsx | 6 ++++++ components/table/hooks/useSelection.tsx | 9 ++++++--- components/table/interface.tsx | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/table/__tests__/type.test.tsx b/components/table/__tests__/type.test.tsx index d19368c6ce..0e33298a06 100644 --- a/components/table/__tests__/type.test.tsx +++ b/components/table/__tests__/type.test.tsx @@ -24,6 +24,12 @@ describe('Table.typescript', () => { ); expect(table).toBeTruthy(); }); + it('selections', () => { + const table = ( + + ); + expect(table).toBeTruthy(); + }); }); describe('Table.typescript types', () => { diff --git a/components/table/hooks/useSelection.tsx b/components/table/hooks/useSelection.tsx index 1aa05f024e..7c2f9076e2 100644 --- a/components/table/hooks/useSelection.tsx +++ b/components/table/hooks/useSelection.tsx @@ -21,8 +21,8 @@ import { const EMPTY_LIST: any[] = []; // TODO: warning if use ajax!!! -export const SELECTION_ALL = 'SELECT_ALL'; -export const SELECTION_INVERT = 'SELECT_INVERT'; +export const SELECTION_ALL = 'SELECT_ALL' as const; +export const SELECTION_INVERT = 'SELECT_INVERT' as const; function getFixedType(column: ColumnsType[number]): FixedType | undefined { return column && column.fixed; @@ -41,7 +41,10 @@ interface UseSelectionConfig { getPopupContainer?: GetPopupContainer; } -type INTERNAL_SELECTION_ITEM = SelectionItem | typeof SELECTION_ALL | typeof SELECTION_INVERT; +export type INTERNAL_SELECTION_ITEM = + | SelectionItem + | typeof SELECTION_ALL + | typeof SELECTION_INVERT; function flattenData( data: RecordType[] | undefined, diff --git a/components/table/interface.tsx b/components/table/interface.tsx index 0fbadf5387..d51c58c8ad 100644 --- a/components/table/interface.tsx +++ b/components/table/interface.tsx @@ -6,6 +6,7 @@ import { } from 'rc-table/lib/interface'; import { CheckboxProps } from '../checkbox'; import { PaginationConfig } from '../pagination'; +import { INTERNAL_SELECTION_ITEM } from './hooks/useSelection'; export { GetRowKey, ExpandableConfig }; @@ -130,7 +131,7 @@ export interface TableRowSelection { onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void; /** @deprecated This function is meaningless and should use `onChange` instead */ onSelectInvert?: (selectedRowKeys: Key[]) => void; - selections?: SelectionItem[] | boolean; + selections?: INTERNAL_SELECTION_ITEM[] | boolean; hideDefaultSelections?: boolean; fixed?: boolean; columnWidth?: string | number;