Skip to content

Commit 212b1ee

Browse files
authored
type: fix master CI fail (ant-design#48044)
1 parent 15532f9 commit 212b1ee

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

components/table/__tests__/Table.test.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ describe('Table', () => {
153153
it('should not crash when dataSource is array with none-object items', () => {
154154
render(
155155
<Table
156-
columns={[
157-
{
158-
title: 'name',
159-
},
160-
]}
156+
columns={[{ title: 'name' }]}
161157
dataSource={['1', 2, undefined, {}, null, true, false, 0] as TableProps<any>['dataSource']}
162158
/>,
163159
);
@@ -245,28 +241,28 @@ describe('Table', () => {
245241

246242
it('warn about rowKey when using index parameter', () => {
247243
warnSpy.mockReset();
248-
const columns = [
244+
const columns: TableProps<any>['columns'] = [
249245
{
250246
title: 'Name',
251247
key: 'name',
252248
dataIndex: 'name',
253249
},
254250
];
255-
render(<Table columns={columns} rowKey={(record, index) => record.key + index} />);
251+
render(<Table columns={columns} rowKey={(record, index) => `${record.key}${index}`} />);
256252
expect(warnSpy).toHaveBeenCalledWith(
257253
'Warning: [antd: Table] `index` parameter of `rowKey` function is deprecated. There is no guarantee that it will work as expected.',
258254
);
259255
});
260256
it('not warn about rowKey', () => {
261257
warnSpy.mockReset();
262-
const columns = [
258+
const columns: TableProps<any>['columns'] = [
263259
{
264260
title: 'Name',
265261
key: 'name',
266262
dataIndex: 'name',
267263
},
268264
];
269-
render(<Table columns={columns} rowKey={(record) => record.key} />);
265+
render(<Table columns={columns} rowKey={(record) => record.key as string} />);
270266
expect(warnSpy).not.toHaveBeenCalled();
271267
});
272268

components/table/hooks/useSorter.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import * as React from 'react';
12
import CaretDownOutlined from '@ant-design/icons/CaretDownOutlined';
23
import CaretUpOutlined from '@ant-design/icons/CaretUpOutlined';
34
import classNames from 'classnames';
45
import KeyCode from 'rc-util/lib/KeyCode';
5-
import * as React from 'react';
6+
67
import type { TooltipProps } from '../../tooltip';
78
import Tooltip from '../../tooltip';
89
import type {
@@ -257,21 +258,26 @@ function injectSorter<RecordType>(
257258
});
258259
}
259260

260-
function stateToInfo<RecordType>(sorterStates: SortState<RecordType>) {
261+
const stateToInfo = <RecordType extends any>(
262+
sorterStates: SortState<RecordType>,
263+
): SorterResult<RecordType> => {
261264
const { column, sortOrder } = sorterStates;
262265
return { column, order: sortOrder, field: column.dataIndex, columnKey: column.key };
263-
}
266+
};
264267

265268
function generateSorterInfo<RecordType>(
266269
sorterStates: SortState<RecordType>[],
267270
): SorterResult<RecordType> | SorterResult<RecordType>[] {
268-
const list = sorterStates.filter(({ sortOrder }) => sortOrder).map(stateToInfo);
271+
const list = sorterStates
272+
.filter(({ sortOrder }) => sortOrder)
273+
.map<SorterResult<RecordType>>(stateToInfo);
269274

270275
// =========== Legacy compatible support ===========
271276
// https://github.com/ant-design/ant-design/pull/19226
272277
if (list.length === 0 && sorterStates.length) {
278+
const lastIndex = sorterStates.length - 1;
273279
return {
274-
...stateToInfo(sorterStates[sorterStates.length - 1]),
280+
...stateToInfo(sorterStates[lastIndex]),
275281
column: undefined,
276282
};
277283
}
@@ -366,7 +372,7 @@ export default function useFilterSorter<RecordType>({
366372
collectSortStates(mergedColumns, true),
367373
);
368374

369-
const mergedSorterStates = React.useMemo(() => {
375+
const mergedSorterStates = React.useMemo<SortState<RecordType>[]>(() => {
370376
let validate = true;
371377
const collectedStates = collectSortStates(mergedColumns, false);
372378

@@ -426,9 +432,8 @@ export default function useFilterSorter<RecordType>({
426432
};
427433
}, [mergedSorterStates]);
428434

429-
function triggerSorter(sortState: SortState<RecordType>) {
430-
let newSorterStates;
431-
435+
const triggerSorter = (sortState: SortState<RecordType>) => {
436+
let newSorterStates: SortState<RecordType>[];
432437
if (
433438
sortState.multiplePriority === false ||
434439
!mergedSorterStates.length ||
@@ -441,10 +446,9 @@ export default function useFilterSorter<RecordType>({
441446
sortState,
442447
];
443448
}
444-
445449
setSortStates(newSorterStates);
446450
onSorterChange(generateSorterInfo(newSorterStates), newSorterStates);
447-
}
451+
};
448452

449453
const transformColumns = (innerColumns: ColumnsType<RecordType>) =>
450454
injectSorter(

0 commit comments

Comments
 (0)