diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 212536d5b28e..a8c524f22e34 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -61,7 +61,7 @@ interface ChangeEventInfo { total?: number; }; filters: Record; - sorter: SorterResult | SorterResult[]; + sorter: SorterResult | SorterResult; filterStates: FilterState[]; sorterStates: SortState[]; @@ -92,7 +92,7 @@ export interface TableProps onChange?: ( pagination: TablePaginationConfig, filters: Record, - sorter: SorterResult | SorterResult[], + sorter: SorterResult | SorterResult, extra: TableCurrentDataSource, ) => void; rowSelection?: TableRowSelection; @@ -263,7 +263,7 @@ function InternalTable( // ============================ Sorter ============================= const onSorterChange = ( - sorter: SorterResult | SorterResult[], + sorter: SorterResult | SorterResult, sorterStates: SortState[], ) => { triggerOnChange( diff --git a/components/table/__tests__/type.test.tsx b/components/table/__tests__/type.test.tsx index a064b0f69fe1..e33dad2f8f66 100644 --- a/components/table/__tests__/type.test.tsx +++ b/components/table/__tests__/type.test.tsx @@ -36,6 +36,12 @@ describe('Table.typescript', () => { const table = dataSource={[{ key: 'Bamboo' }]} />; expect(table).toBeTruthy(); }); + + it('Sorter types', () => { + const table = sorter.field} />; + + expect(table).toBeTruthy(); + }); }); describe('Table.typescript types', () => { diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index 2c08a33ab642..9784f92ded0c 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -247,7 +247,7 @@ function stateToInfo(sorterStates: SortState) { function generateSorterInfo( sorterStates: SortState[], -): SorterResult | SorterResult[] { +): SorterResult | SorterResult { const list = sorterStates.filter(({ sortOrder }) => sortOrder).map(stateToInfo); // =========== Legacy compatible support =========== @@ -259,11 +259,7 @@ function generateSorterInfo( }; } - if (list.length <= 1) { - return list[0] || {}; - } - - return list; + return list[0] || {}; } export function getSortData( @@ -324,7 +320,7 @@ interface SorterConfig { prefixCls: string; mergedColumns: ColumnsType; onSorterChange: ( - sorterResult: SorterResult | SorterResult[], + sorterResult: SorterResult | SorterResult, sortStates: SortState[], ) => void; sortDirections: SortOrder[]; @@ -343,7 +339,7 @@ export default function useFilterSorter({ TransformColumns, SortState[], ColumnTitleProps, - () => SorterResult | SorterResult[], + () => SorterResult | SorterResult, ] { const [sortStates, setSortStates] = React.useState[]>( collectSortStates(mergedColumns, true),