From 08f25f0c8f641d966ba62eb52b2296e4570e3415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 28 Jan 2021 01:21:58 +0800 Subject: [PATCH] chore: Update Table ts definition (#29084) * chore: bump rc-table ver * chore: Fix ts definition * docs: fix doc --- components/table/Table.tsx | 9 +++++++-- components/table/hooks/useLazyKVMap.ts | 6 +++--- components/table/hooks/useSorter.tsx | 2 +- components/table/interface.tsx | 2 +- components/table/util.ts | 2 +- docs/spec/introduce.en-US.md | 2 +- docs/spec/introduce.zh-CN.md | 2 +- package.json | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 44e6e549c9..067d9872a9 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -152,7 +152,7 @@ function Table(props: TableProps) { ); const mergedSize = customizeSize || size; const tableLocale = { ...contextLocale.Table, ...locale } as TableLocale; - const rawData: RecordType[] = dataSource || EMPTY_LIST; + const rawData: readonly RecordType[] = dataSource || EMPTY_LIST; const { getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('table', customizePrefixCls); @@ -236,7 +236,12 @@ function Table(props: TableProps) { } }; - /** Controlled state in `columns` is not a good idea that makes too many code (1000+ line?) to read state out and then put it back to title render. Move these code into `hooks` but still too complex. We should provides Table props like `sorter` & `filter` to handle control in next big version. */ + /** + * Controlled state in `columns` is not a good idea that makes too many code (1000+ line?) to + * read state out and then put it back to title render. Move these code into `hooks` but still + * too complex. We should provides Table props like `sorter` & `filter` to handle control in next + * big version. + */ // ============================ Sorter ============================= const onSorterChange = ( diff --git a/components/table/hooks/useLazyKVMap.ts b/components/table/hooks/useLazyKVMap.ts index 83f550aadf..747aaac685 100644 --- a/components/table/hooks/useLazyKVMap.ts +++ b/components/table/hooks/useLazyKVMap.ts @@ -2,14 +2,14 @@ import * as React from 'react'; import { Key, GetRowKey } from '../interface'; interface MapCache { - data?: RecordType[]; + data?: readonly RecordType[]; childrenColumnName?: string; kvMap?: Map; getRowKey?: Function; } export default function useLazyKVMap( - data: RecordType[], + data: readonly RecordType[], childrenColumnName: string, getRowKey: GetRowKey, ) { @@ -25,7 +25,7 @@ export default function useLazyKVMap( const kvMap = new Map(); /* eslint-disable no-inner-declarations */ - function dig(records: RecordType[]) { + function dig(records: readonly RecordType[]) { records.forEach((record, index) => { const rowKey = getRowKey(record, index); kvMap.set(rowKey, record); diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index 5fe86fe7bb..0078d77494 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -244,7 +244,7 @@ function generateSorterInfo( } export function getSortData( - data: RecordType[], + data: readonly RecordType[], sortStates: SortState[], childrenColumnName: string, ): RecordType[] { diff --git a/components/table/interface.tsx b/components/table/interface.tsx index cd92adbf4b..31b104968e 100644 --- a/components/table/interface.tsx +++ b/components/table/interface.tsx @@ -175,7 +175,7 @@ export interface TableCurrentDataSource { export interface SorterResult { column?: ColumnType; order?: SortOrder; - field?: Key | Key[]; + field?: Key | readonly Key[]; columnKey?: Key; } diff --git a/components/table/util.ts b/components/table/util.ts index 03285adc37..c949fb59e7 100644 --- a/components/table/util.ts +++ b/components/table/util.ts @@ -6,7 +6,7 @@ export function getColumnKey(column: ColumnType, default return column.key; } if (column.dataIndex) { - return Array.isArray(column.dataIndex) ? column.dataIndex.join('.') : column.dataIndex; + return (Array.isArray(column.dataIndex) ? column.dataIndex.join('.') : column.dataIndex) as Key; } return defaultKey; diff --git a/docs/spec/introduce.en-US.md b/docs/spec/introduce.en-US.md index 4418f80846..9fa5588c7c 100644 --- a/docs/spec/introduce.en-US.md +++ b/docs/spec/introduce.en-US.md @@ -98,7 +98,7 @@ ReactDOM.render(, mountNode); - Hacknews: [Show HN: Antd – A set of high-quality React components](https://news.ycombinator.com/item?id=13053137) - Alligator: [Crafting Beautiful UIs in React Using Ant Design](https://alligator.io/react/beautiful-uis-ant-design/) - [Introduction to Ant Design](https://blog.logrocket.com/introduction-to-ant-design/) -- [Build a React App with Ant Design Principles ](https://developer.okta.com/blog/2020/09/16/ant-design-react-app) +- [Build a React App with Ant Design Principles](https://developer.okta.com/blog/2020/09/16/ant-design-react-app) - [Meet Antd, an enterprise React UI library](https://medium.com/javascript-in-plain-english/antd-library-what-why-useful-or-not-5fec225b639d) ## How to Contribute diff --git a/docs/spec/introduce.zh-CN.md b/docs/spec/introduce.zh-CN.md index 09fde98cc8..4841284a33 100644 --- a/docs/spec/introduce.zh-CN.md +++ b/docs/spec/introduce.zh-CN.md @@ -100,7 +100,7 @@ ReactDOM.render(, mountNode); - Alligator: [Crafting Beautiful UIs in React Using Ant Design](https://alligator.io/react/beautiful-uis-ant-design/) - [漫谈 Material Design & Ant Design](http://dwbbb.com/blog/MaterialDesignAntDesign/) - [Introduction to Ant Design](https://blog.logrocket.com/introduction-to-ant-design/) -- [Build a React App with Ant Design Principles ](https://developer.okta.com/blog/2020/09/16/ant-design-react-app) +- [Build a React App with Ant Design Principles](https://developer.okta.com/blog/2020/09/16/ant-design-react-app) - [Meet Antd, an enterprise React UI library](https://medium.com/javascript-in-plain-english/antd-library-what-why-useful-or-not-5fec225b639d) ## 如何贡献 diff --git a/package.json b/package.json index c52da48156..78562c7504 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,7 @@ "rc-slider": "~9.7.1", "rc-steps": "~4.1.0", "rc-switch": "~3.2.0", - "rc-table": "~7.12.0", + "rc-table": "~7.13.0", "rc-tabs": "~11.7.0", "rc-textarea": "~0.3.0", "rc-tooltip": "~5.0.0",