From 857ee24e382bd93202c561a4e48518d3b9def0d1 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sun, 11 Aug 2024 10:58:13 +0800 Subject: [PATCH] type(Table): TypeScript improvement (#50351) * type: Table TypeScript improvement * type: Table TypeScript improvement * type: Table TypeScript improvement * fix: fix demo * fix: fix demo * fix: fix type * fix: fix type * fix: fix type * fix: fix type --- components/table/Column.ts | 8 +- components/table/ColumnGroup.ts | 8 +- components/table/ExpandIcon.tsx | 15 +-- components/table/InternalTable.tsx | 21 ++-- components/table/RcTable/VirtualTable.tsx | 10 +- components/table/RcTable/index.tsx | 10 +- components/table/demo/ajax.tsx | 4 +- components/table/demo/edit-row.tsx | 2 +- .../demo/row-selection-and-operation.tsx | 2 +- .../table/demo/row-selection-custom-debug.tsx | 2 +- .../table/demo/row-selection-custom.tsx | 2 +- components/table/demo/row-selection-debug.tsx | 2 +- components/table/demo/tree-data.tsx | 2 +- .../table/hooks/useFilter/FilterDropdown.tsx | 9 +- .../table/hooks/useFilter/FilterSearch.tsx | 16 ++- .../table/hooks/useFilter/FilterWrapper.tsx | 26 ++-- components/table/hooks/useFilter/index.tsx | 70 ++++++----- components/table/hooks/useLazyKVMap.ts | 15 ++- components/table/hooks/useSorter.tsx | 111 ++++++++++-------- components/table/hooks/useTitleColumns.ts | 38 +++--- components/table/interface.ts | 25 ++-- components/table/util.ts | 30 +++-- components/transfer/demo/component-token.tsx | 2 +- 23 files changed, 233 insertions(+), 197 deletions(-) diff --git a/components/table/Column.ts b/components/table/Column.ts index 75633088d2..0d0761f282 100644 --- a/components/table/Column.ts +++ b/components/table/Column.ts @@ -1,14 +1,14 @@ +import type { AnyObject } from '../_util/type'; import type { ColumnType } from './interface'; -export interface ColumnProps extends ColumnType { +export interface ColumnProps + extends ColumnType { children?: null; } /* istanbul ignore next */ /** This is a syntactic sugar for `columns` prop. So HOC will not work on this. */ // eslint-disable-next-line no-unused-vars -function Column(_: ColumnProps) { - return null; -} +const Column = (_: ColumnProps) => null; export default Column; diff --git a/components/table/ColumnGroup.ts b/components/table/ColumnGroup.ts index 75e6d405fb..3c98159395 100644 --- a/components/table/ColumnGroup.ts +++ b/components/table/ColumnGroup.ts @@ -1,9 +1,11 @@ import type * as React from 'react'; +import type { AnyObject } from '../_util/type'; import type { ColumnProps } from './Column'; import type { ColumnType } from './interface'; -export interface ColumnGroupProps extends Omit, 'children'> { +export interface ColumnGroupProps + extends Omit, 'children'> { children: | React.ReactElement> | React.ReactElement>[]; @@ -12,8 +14,6 @@ export interface ColumnGroupProps extends Omit(_: ColumnGroupProps) { - return null; -} +const ColumnGroup = (_: ColumnGroupProps) => null; export default ColumnGroup; diff --git a/components/table/ExpandIcon.tsx b/components/table/ExpandIcon.tsx index c3810ce376..604db8b424 100644 --- a/components/table/ExpandIcon.tsx +++ b/components/table/ExpandIcon.tsx @@ -1,26 +1,21 @@ import * as React from 'react'; import classNames from 'classnames'; +import type { AnyObject } from '../_util/type'; import type { TableLocale } from './interface'; -interface DefaultExpandIconProps { +interface DefaultExpandIconProps { prefixCls: string; - onExpand: (record: RecordType, e: React.MouseEvent) => void; record: RecordType; expanded: boolean; expandable: boolean; + onExpand: (record: RecordType, e: React.MouseEvent) => void; } function renderExpandIcon(locale: TableLocale) { - return function expandIcon({ - prefixCls, - onExpand, - record, - expanded, - expandable, - }: DefaultExpandIconProps) { + return (props: DefaultExpandIconProps) => { + const { prefixCls, onExpand, record, expanded, expandable } = props; const iconPrefix = `${prefixCls}-row-expand-icon`; - return (