From 180ed017f85cc7a38019540f4f185d33d573bec6 Mon Sep 17 00:00:00 2001 From: "jiang.an" Date: Wed, 12 Jun 2019 17:46:21 +0800 Subject: [PATCH 01/38] fix: prop headerRender should be optional for component Calendar --- components/calendar/Header.tsx | 10 ++++++---- components/calendar/index.tsx | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/components/calendar/Header.tsx b/components/calendar/Header.tsx index e305d0ad3d..961fcd375b 100644 --- a/components/calendar/Header.tsx +++ b/components/calendar/Header.tsx @@ -12,6 +12,8 @@ export interface RenderHeader { onTypeChange: (type: string) => void; } +export type HeaderRender = (headerRender: RenderHeader) => React.ReactNode; + export interface HeaderProps { prefixCls?: string; locale?: any; @@ -23,7 +25,7 @@ export interface HeaderProps { onTypeChange?: (type: string) => void; value: moment.Moment; validRange?: [moment.Moment, moment.Moment]; - headerRender: (header: RenderHeader) => React.ReactNode; + headerRender?: HeaderRender; } export default class Header extends React.Component { @@ -178,8 +180,8 @@ export default class Header extends React.Component { ); }; - headerRenderCustom = (): React.ReactNode => { - const { headerRender, type, onValueChange, value } = this.props; + headerRenderCustom = (headerRender: HeaderRender): React.ReactNode => { + const { type, onValueChange, value } = this.props; return headerRender({ value, @@ -194,7 +196,7 @@ export default class Header extends React.Component { const typeSwitch = this.getTypeSwitch(); const { yearReactNode, monthReactNode } = this.getMonthYearSelections(getPrefixCls); return headerRender ? ( - this.headerRenderCustom() + this.headerRenderCustom(headerRender) ) : (
{yearReactNode} diff --git a/components/calendar/index.tsx b/components/calendar/index.tsx index 25ca8e6ff9..ed8fbcf8ce 100644 --- a/components/calendar/index.tsx +++ b/components/calendar/index.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import * as PropTypes from 'prop-types'; import * as moment from 'moment'; import FullCalendar from 'rc-calendar/lib/FullCalendar'; -import Header, { RenderHeader } from './Header'; +import Header, { HeaderRender } from './Header'; import enUS from './locale/en_US'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; @@ -41,7 +41,7 @@ export interface CalendarProps { onChange?: (date?: moment.Moment) => void; disabledDate?: (current: moment.Moment) => boolean; validRange?: [moment.Moment, moment.Moment]; - headerRender: (header: RenderHeader) => React.ReactNode; + headerRender?: HeaderRender; } export interface CalendarState { @@ -56,7 +56,6 @@ class Calendar extends React.Component { onSelect: noop, onPanelChange: noop, onChange: noop, - headerRender: null, }; static propTypes = { @@ -73,6 +72,7 @@ class Calendar extends React.Component { value: PropTypes.object as PropTypes.Requireable, onSelect: PropTypes.func, onChange: PropTypes.func, + headerRender: PropTypes.func, }; static getDerivedStateFromProps(nextProps: CalendarProps) { From f1ee189bd2b187b8a91d158067ac5db7dd9c9ea4 Mon Sep 17 00:00:00 2001 From: Zzzen <843968788@qq.com> Date: Sun, 16 Jun 2019 20:51:47 +0800 Subject: [PATCH 02/38] eliminate `any` type in exported interfaces.#14044 --- components/_util/interopDefault.ts | 1 + components/anchor/AnchorLink.tsx | 2 +- components/auto-complete/InputElement.tsx | 2 +- components/auto-complete/index.tsx | 6 +-- components/avatar/index.tsx | 2 +- components/back-top/index.tsx | 2 +- components/badge/ScrollNumber.tsx | 2 +- components/breadcrumb/Breadcrumb.tsx | 34 +++++++-------- components/button/button.tsx | 10 ++--- components/calendar/Header.tsx | 2 +- components/checkbox/Checkbox.tsx | 12 +++--- components/checkbox/Group.tsx | 2 +- components/collapse/Collapse.tsx | 2 +- components/comment/index.tsx | 2 +- components/date-picker/InputIcon.tsx | 2 +- components/date-picker/interface.tsx | 2 +- components/dropdown/dropdown-button.tsx | 2 +- components/form/Form.tsx | 42 +++++++++++-------- components/icon/IconFont.tsx | 2 +- components/input/Group.tsx | 2 +- components/input/Search.tsx | 2 +- components/list/index.tsx | 2 +- components/locale-provider/LocaleReceiver.tsx | 2 +- components/mention/index.tsx | 25 ++++++----- components/mentions/index.tsx | 40 +++++++++--------- components/menu/index.tsx | 8 ++-- components/message/index.tsx | 6 +-- components/modal/Modal.tsx | 11 ++--- components/popconfirm/index.tsx | 6 +-- components/radio/interface.tsx | 8 ++-- components/rate/index.tsx | 4 +- components/select/index.tsx | 21 ++++++---- components/slider/index.tsx | 2 +- components/spin/index.tsx | 6 +-- components/steps/index.tsx | 2 +- components/switch/index.tsx | 4 +- .../table/FilterDropdownMenuWrapper.tsx | 2 +- components/table/Table.tsx | 2 +- components/table/createStore.tsx | 2 +- components/table/filterDropdown.tsx | 2 +- components/table/interface.tsx | 42 +++++++++++-------- components/tabs/index.tsx | 8 ++-- components/tooltip/placements.tsx | 4 +- components/transfer/index.tsx | 4 +- components/transfer/search.tsx | 6 +-- components/tree-select/index.tsx | 9 ++-- components/tree-select/interface.tsx | 22 +++++----- components/tree/Tree.tsx | 14 +++---- components/upload/interface.tsx | 6 +-- 49 files changed, 216 insertions(+), 189 deletions(-) diff --git a/components/_util/interopDefault.ts b/components/_util/interopDefault.ts index 594bdd92d1..474e278571 100644 --- a/components/_util/interopDefault.ts +++ b/components/_util/interopDefault.ts @@ -1,4 +1,5 @@ // https://github.com/moment/moment/issues/3650 +// since we are using ts 3.5.1, it should be safe to remove. export default function interopDefault(m: any) { return m.default || m; } diff --git a/components/anchor/AnchorLink.tsx b/components/anchor/AnchorLink.tsx index 9e84899a81..a1c553bc6a 100644 --- a/components/anchor/AnchorLink.tsx +++ b/components/anchor/AnchorLink.tsx @@ -9,7 +9,7 @@ export interface AnchorLinkProps { prefixCls?: string; href: string; title: React.ReactNode; - children?: any; + children?: React.ReactNode; className?: string; } diff --git a/components/auto-complete/InputElement.tsx b/components/auto-complete/InputElement.tsx index fbedf5bc34..42d403b906 100644 --- a/components/auto-complete/InputElement.tsx +++ b/components/auto-complete/InputElement.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; export interface InputElementProps { - children: React.ReactElement; + children: React.ReactElement; } export default class InputElement extends React.Component { diff --git a/components/auto-complete/index.tsx b/components/auto-complete/index.tsx index 918d488c08..8727ee0dd5 100755 --- a/components/auto-complete/index.tsx +++ b/components/auto-complete/index.tsx @@ -17,8 +17,8 @@ export type DataSourceItemType = | React.ReactElement; export interface AutoCompleteInputProps { - onChange?: React.FormEventHandler; - value: any; + onChange?: React.FormEventHandler; + value: unknown; } export type ValidInputElement = @@ -34,7 +34,7 @@ export interface AutoCompleteProps extends AbstractSelectProps { backfill?: boolean; optionLabelProp?: string; onChange?: (value: SelectValue) => void; - onSelect?: (value: SelectValue, option: Object) => any; + onSelect?: (value: SelectValue, option: Object) => unknown; onBlur?: (value: SelectValue) => void; onFocus?: () => void; children?: diff --git a/components/avatar/index.tsx b/components/avatar/index.tsx index 9bc3db5e49..bef60e80ac 100644 --- a/components/avatar/index.tsx +++ b/components/avatar/index.tsx @@ -20,7 +20,7 @@ export interface AvatarProps { style?: React.CSSProperties; prefixCls?: string; className?: string; - children?: any; + children?: React.ReactNode; alt?: string; /* callback when img load error */ /* return false to prevent Avatar show default fallback behavior, then you can do fallback by your self*/ diff --git a/components/back-top/index.tsx b/components/back-top/index.tsx index 3b26eb5485..8a9b516273 100755 --- a/components/back-top/index.tsx +++ b/components/back-top/index.tsx @@ -25,7 +25,7 @@ function getDefaultTarget() { export interface BackTopProps { visibilityHeight?: number; - onClick?: React.MouseEventHandler; + onClick?: React.MouseEventHandler; target?: () => HTMLElement | Window; prefixCls?: string; className?: string; diff --git a/components/badge/ScrollNumber.tsx b/components/badge/ScrollNumber.tsx index c5bd287430..f2c5ed30ff 100644 --- a/components/badge/ScrollNumber.tsx +++ b/components/badge/ScrollNumber.tsx @@ -22,7 +22,7 @@ export interface ScrollNumberProps { prefixCls?: string; className?: string; count?: string | number | null; - displayComponent?: React.ReactElement; + displayComponent?: React.ReactElement; component?: string; onAnimated?: Function; style?: React.CSSProperties; diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx index 24d3066e26..5b58f7fb4c 100755 --- a/components/breadcrumb/Breadcrumb.tsx +++ b/components/breadcrumb/Breadcrumb.tsx @@ -17,12 +17,12 @@ export interface Route { export interface BreadcrumbProps { prefixCls?: string; routes?: Route[]; - params?: any; + params?: unknown; separator?: React.ReactNode; itemRender?: ( - route: any, - params: any, - routes: Array, + route: Route, + params: unknown, + routes: Array, paths: Array, ) => React.ReactNode; style?: React.CSSProperties; @@ -72,21 +72,21 @@ export default class Breadcrumb extends React.Component { } getPath = (path: string, params: any) => { - path = (path || '').replace(/^\//, ''); - Object.keys(params).forEach(key => { - path = path.replace(`:${key}`, params[key]); - }); - return path; - } + path = (path || '').replace(/^\//, ''); + Object.keys(params).forEach(key => { + path = path.replace(`:${key}`, params[key]); + }); + return path; + }; addChildPath = (paths: string[], childPath: string = '', params: any) => { const originalPaths = [...paths]; const path = this.getPath(childPath, params); if (path) { - originalPaths.push(path); + originalPaths.push(path); } return originalPaths; - } + }; genForRoutes = ({ routes = [], @@ -107,12 +107,10 @@ export default class Breadcrumb extends React.Component { overlay = ( {route.children.map(child => ( - - { - itemRender(child, params, routes, this.addChildPath(paths, child.path, params)) - } - - ))} + + {itemRender(child, params, routes, this.addChildPath(paths, child.path, params))} + + ))} ); } diff --git a/components/button/button.tsx b/components/button/button.tsx index abbf9ebf0b..b44ab0373a 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -91,15 +91,15 @@ export interface BaseButtonProps { export type AnchorButtonProps = { href: string; target?: string; - onClick?: React.MouseEventHandler; + onClick?: React.MouseEventHandler; } & BaseButtonProps & - Omit, 'type'>; + Omit, 'type' | 'onClick'>; export type NativeButtonProps = { htmlType?: ButtonHTMLType; - onClick?: React.MouseEventHandler; + onClick?: React.MouseEventHandler; } & BaseButtonProps & - Omit, 'type'>; + Omit, 'type' | 'onClick'>; export type ButtonProps = Partial; @@ -289,7 +289,7 @@ class Button extends React.Component { const buttonNode = (