From 4c84c41da0074f86a0491c3cc68e54995609220e Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 23 Jun 2019 15:27:06 +0800 Subject: [PATCH 1/5] :bug: Revert Form type `unknown` to `any` close #17245 --- components/form/Form.tsx | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/components/form/Form.tsx b/components/form/Form.tsx index 1855c9a578..9aad66952a 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -13,15 +13,15 @@ import { FIELD_META_PROP, FIELD_DATA_PROP } from './constants'; import { FormContext } from './context'; import { FormWrappedProps } from './interface'; -type FormCreateOptionMessagesCallback = (...args: unknown[]) => string; +type FormCreateOptionMessagesCallback = (...args: any[]) => string; interface FormCreateOptionMessages { [messageId: string]: string | FormCreateOptionMessagesCallback | FormCreateOptionMessages; } export interface FormCreateOption { - onFieldsChange?: (props: T, fields: unknown, allFields: unknown) => void; - onValuesChange?: (props: T, changedValues: unknown, allValues: unknown) => void; + onFieldsChange?: (props: T, fields: any, allFields: any) => void; + onValuesChange?: (props: T, changedValues: any, allValues: any) => void; mapPropsToFields?: (props: T) => void; validateMessages?: FormCreateOptionMessages; withRef?: boolean; @@ -71,30 +71,24 @@ export type ValidationRule = { /** validate from a regular expression */ pattern?: RegExp; /** transform a value before validation */ - transform?: (value: unknown) => unknown; + transform?: (value: any) => any; /** custom validate function (Note: callback must be called) */ - validator?: ( - rule: unknown, - value: unknown, - callback: unknown, - source?: unknown, - options?: unknown, - ) => unknown; + validator?: (rule: any, value: any, callback: any, source?: any, options?: any) => any; }; -export type ValidateCallback = (errors: unknown, values: V) => void; +export type ValidateCallback = (errors: any, values: V) => void; export type GetFieldDecoratorOptions = { /** 子节点的值的属性,如 Checkbox 的是 'checked' */ valuePropName?: string; /** 子节点的初始值,类型、可选值均由子节点决定 */ - initialValue?: unknown; + initialValue?: any; /** 收集子节点的值的时机 */ trigger?: string; /** 可以把 onChange 的参数转化为控件的值,例如 DatePicker 可设为:(date, dateString) => dateString */ - getValueFromEvent?: (...args: unknown[]) => unknown; + getValueFromEvent?: (...args: any[]) => any; /** Get the component props according to field value. */ - getValueProps?: (value: unknown) => unknown; + getValueProps?: (value: any) => any; /** 校验子节点值的时机 */ validateTrigger?: string | string[]; /** 校验规则,参见 [async-validator](https://github.com/yiminghe/async-validator) */ @@ -102,7 +96,7 @@ export type GetFieldDecoratorOptions = { /** 是否和其他控件互斥,特别用于 Radio 单选控件 */ exclusive?: boolean; /** Normalize value to form component */ - normalize?: (value: unknown, prevValue: unknown, allValues: unknown) => unknown; + normalize?: (value: any, prevValue: any, allValues: any) => any; /** Whether stop validate on first rule of error for this field. */ validateFirst?: boolean; /** 是否一直保留子节点的信息 */ @@ -141,11 +135,11 @@ export type ValidateFieldsOptions = { }; // function create -export type WrappedFormUtils = { +export type WrappedFormUtils = { /** 获取一组输入控件的值,如不传入参数,则获取全部组件的值 */ - getFieldsValue(fieldNames?: Array): { [field: string]: unknown }; + getFieldsValue(fieldNames?: Array): { [field: string]: any }; /** 获取一个输入控件的值 */ - getFieldValue(fieldName: string): unknown; + getFieldValue(fieldName: string): any; /** 设置一组输入控件的值 */ setFieldsValue(obj: Object): void; /** 设置一组输入控件的值 */ @@ -192,17 +186,15 @@ export type WrappedFormUtils = { ): (node: React.ReactNode) => React.ReactNode; }; -export interface WrappedFormInternalProps { +export interface WrappedFormInternalProps { form: WrappedFormUtils; } export interface RcBaseFormProps { - wrappedComponentRef?: unknown; + wrappedComponentRef?: any; } -export interface FormComponentProps - extends WrappedFormInternalProps, - RcBaseFormProps { +export interface FormComponentProps extends WrappedFormInternalProps, RcBaseFormProps { form: WrappedFormUtils; } From 936fea5769402d075b7730d257bf143c8157e206 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 24 Jun 2019 11:13:55 +0800 Subject: [PATCH 2/5] :bug: Fix onRow return types https://github.com/ant-design/ant-design/issues/17245#issuecomment-504807714 --- components/table/interface.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/components/table/interface.tsx b/components/table/interface.tsx index eb884d6a75..7b8d180715 100644 --- a/components/table/interface.tsx +++ b/components/table/interface.tsx @@ -135,6 +135,7 @@ export interface TableEventListeners { onContextMenu?: (arg: React.SyntheticEvent) => void; onMouseEnter?: (arg: React.SyntheticEvent) => void; onMouseLeave?: (arg: React.SyntheticEvent) => void; + [name: string]: any; // https://github.com/ant-design/ant-design/issues/17245#issuecomment-504807714 } export interface TableProps { From 57c28def68350c0480569da7aa7c1d8795901940 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 24 Jun 2019 11:29:58 +0800 Subject: [PATCH 3/5] revert unknown to any --- components/auto-complete/InputElement.tsx | 2 +- components/auto-complete/index.tsx | 6 +++--- components/breadcrumb/Breadcrumb.tsx | 4 ++-- components/button/button.tsx | 4 ++-- components/checkbox/Checkbox.tsx | 2 +- components/checkbox/Group.tsx | 2 +- components/date-picker/interface.tsx | 2 +- components/icon/IconFont.tsx | 2 +- components/mention/index.tsx | 16 ++++++++-------- components/mentions/index.tsx | 2 +- components/menu/index.tsx | 4 ++-- components/message/index.tsx | 2 +- components/modal/Modal.tsx | 6 +++--- components/radio/interface.tsx | 8 ++++---- components/select/index.tsx | 6 +++--- components/table/Table.tsx | 2 +- components/table/filterDropdown.tsx | 2 +- components/table/interface.tsx | 10 +++++----- components/tabs/index.tsx | 2 +- components/tree-select/interface.tsx | 12 ++++++------ components/tree/Tree.tsx | 2 +- 21 files changed, 49 insertions(+), 49 deletions(-) diff --git a/components/auto-complete/InputElement.tsx b/components/auto-complete/InputElement.tsx index 42d403b906..fbedf5bc34 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 8727ee0dd5..918d488c08 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: unknown; + onChange?: React.FormEventHandler; + value: any; } 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) => unknown; + onSelect?: (value: SelectValue, option: Object) => any; onBlur?: (value: SelectValue) => void; onFocus?: () => void; children?: diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx index 5b58f7fb4c..7fa95dda1a 100755 --- a/components/breadcrumb/Breadcrumb.tsx +++ b/components/breadcrumb/Breadcrumb.tsx @@ -17,11 +17,11 @@ export interface Route { export interface BreadcrumbProps { prefixCls?: string; routes?: Route[]; - params?: unknown; + params?: any; separator?: React.ReactNode; itemRender?: ( route: Route, - params: unknown, + params: any, routes: Array, paths: Array, ) => React.ReactNode; diff --git a/components/button/button.tsx b/components/button/button.tsx index b44ab0373a..3a4823485e 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -93,13 +93,13 @@ export type AnchorButtonProps = { target?: string; onClick?: React.MouseEventHandler; } & BaseButtonProps & - Omit, 'type' | 'onClick'>; + Omit, 'type' | 'onClick'>; export type NativeButtonProps = { htmlType?: ButtonHTMLType; onClick?: React.MouseEventHandler; } & BaseButtonProps & - Omit, 'type' | 'onClick'>; + Omit, 'type' | 'onClick'>; export type ButtonProps = Partial; diff --git a/components/checkbox/Checkbox.tsx b/components/checkbox/Checkbox.tsx index d9a682602e..a6c3a709bf 100644 --- a/components/checkbox/Checkbox.tsx +++ b/components/checkbox/Checkbox.tsx @@ -20,7 +20,7 @@ export interface AbstractCheckboxProps { onMouseLeave?: React.MouseEventHandler; onKeyPress?: React.KeyboardEventHandler; onKeyDown?: React.KeyboardEventHandler; - value?: unknown; + value?: any; tabIndex?: number; name?: string; children?: React.ReactNode; diff --git a/components/checkbox/Group.tsx b/components/checkbox/Group.tsx index 4446f12d84..24ecfa7e45 100644 --- a/components/checkbox/Group.tsx +++ b/components/checkbox/Group.tsx @@ -39,7 +39,7 @@ export interface CheckboxGroupState { export interface CheckboxGroupContext { checkboxGroup: { toggleOption: (option: CheckboxOptionType) => void; - value: unknown; + value: any; disabled: boolean; }; } diff --git a/components/date-picker/interface.tsx b/components/date-picker/interface.tsx index a5b20bbe68..6e53186244 100644 --- a/components/date-picker/interface.tsx +++ b/components/date-picker/interface.tsx @@ -16,7 +16,7 @@ export interface PickerProps { style?: React.CSSProperties; popupStyle?: React.CSSProperties; dropdownClassName?: string; - locale?: unknown; + locale?: any; size?: 'large' | 'small' | 'default'; getCalendarContainer?: (triggerNode: Element) => HTMLElement; open?: boolean; diff --git a/components/icon/IconFont.tsx b/components/icon/IconFont.tsx index edb7118ac1..3f94a0a72e 100644 --- a/components/icon/IconFont.tsx +++ b/components/icon/IconFont.tsx @@ -5,7 +5,7 @@ const customCache = new Set(); export interface CustomIconOptions { scriptUrl?: string; - extraCommonProps?: { [key: string]: unknown }; + extraCommonProps?: { [key: string]: any }; } export default function create(options: CustomIconOptions = {}): React.SFC { diff --git a/components/mention/index.tsx b/components/mention/index.tsx index a425d118a3..a973060209 100644 --- a/components/mention/index.tsx +++ b/components/mention/index.tsx @@ -14,14 +14,14 @@ export interface MentionProps { prefixCls?: string; suggestionStyle?: React.CSSProperties; defaultSuggestions?: Array; - suggestions?: Array>; - onSearchChange?: (value: string, trigger: string) => unknown; - onChange?: (contentState: unknown) => void; - notFoundContent?: unknown; + suggestions?: Array>; + onSearchChange?: (value: string, trigger: string) => any; + onChange?: (contentState: any) => void; + notFoundContent?: any; loading?: boolean; style?: React.CSSProperties; - defaultValue?: unknown; - value?: unknown; + defaultValue?: any; + value?: any; className?: string; multiLines?: boolean; prefix?: string | string[]; @@ -29,14 +29,14 @@ export interface MentionProps { getSuggestionContainer?: (triggerNode: Element) => HTMLElement; onFocus?: React.FocusEventHandler; onBlur?: React.FocusEventHandler; - onSelect?: (suggestion: string, data?: unknown) => void; + onSelect?: (suggestion: string, data?: any) => void; readOnly?: boolean; disabled?: boolean; placement?: MentionPlacement; } export interface MentionState { - filteredSuggestions?: Array; + filteredSuggestions?: Array; focus?: Boolean; } diff --git a/components/mentions/index.tsx b/components/mentions/index.tsx index 0f9e0c2638..c189fc4ae5 100644 --- a/components/mentions/index.tsx +++ b/components/mentions/index.tsx @@ -19,7 +19,7 @@ export type MentionPlacement = 'top' | 'bottom'; export interface OptionProps { value: string; children: React.ReactNode; - [key: string]: unknown; + [key: string]: any; } export interface MentionProps extends RcMentionsProps { diff --git a/components/menu/index.tsx b/components/menu/index.tsx index 1ebb31a9a5..f52086f583 100644 --- a/components/menu/index.tsx +++ b/components/menu/index.tsx @@ -15,7 +15,7 @@ import raf from '../_util/raf'; export interface SelectParam { key: string; keyPath: Array; - item: unknown; + item: any; domEvent: Event; selectedKeys: Array; } @@ -23,7 +23,7 @@ export interface SelectParam { export interface ClickParam { key: string; keyPath: Array; - item: unknown; + item: any; domEvent: Event; } diff --git a/components/message/index.tsx b/components/message/index.tsx index 08f6931b7c..e64da27109 100755 --- a/components/message/index.tsx +++ b/components/message/index.tsx @@ -39,7 +39,7 @@ function getMessageInstance(callback: (i: any) => void) { type NoticeType = 'info' | 'success' | 'error' | 'warning' | 'loading'; export interface ThenableArgument { - (val: unknown): void; + (val: any): void; } export interface MessageType { diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index dc45e3e801..bdd32b1eae 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -74,7 +74,7 @@ export interface ModalProps { maskStyle?: React.CSSProperties; mask?: boolean; keyboard?: boolean; - wrapProps?: unknown; + wrapProps?: any; prefixCls?: string; } @@ -85,8 +85,8 @@ export interface ModalFuncProps { title?: React.ReactNode; content?: React.ReactNode; // TODO: find out exact types - onOk?: (...args: unknown[]) => unknown; - onCancel?: (...args: unknown[]) => unknown; + onOk?: (...args: any[]) => any; + onCancel?: (...args: any[]) => any; okButtonProps?: NativeButtonProps; cancelButtonProps?: NativeButtonProps; centered?: boolean; diff --git a/components/radio/interface.tsx b/components/radio/interface.tsx index 8e8a3db8a3..5cdb581ff2 100644 --- a/components/radio/interface.tsx +++ b/components/radio/interface.tsx @@ -5,8 +5,8 @@ import { AbstractCheckboxProps } from '../checkbox/Checkbox'; export type RadioGroupButtonStyle = 'outline' | 'solid'; export interface RadioGroupProps extends AbstractCheckboxGroupProps { - defaultValue?: unknown; - value?: unknown; + defaultValue?: any; + value?: any; onChange?: (e: RadioChangeEvent) => void; size?: 'large' | 'default' | 'small'; onMouseEnter?: React.MouseEventHandler; @@ -18,13 +18,13 @@ export interface RadioGroupProps extends AbstractCheckboxGroupProps { } export interface RadioGroupState { - value: unknown; + value: any; } export interface RadioGroupContext { radioGroup: { onChange: React.ChangeEventHandler; - value: unknown; + value: any; disabled: boolean; name: string; }; diff --git a/components/select/index.tsx b/components/select/index.tsx index e9761b39a4..3f0a026681 100755 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -59,9 +59,9 @@ export interface SelectProps extends AbstractSelectProps { firstActiveValue?: string | string[]; onChange?: ( value: T, - option: React.ReactElement | React.ReactElement[], + option: React.ReactElement | React.ReactElement[], ) => void; - onSelect?: (value: T extends (infer I)[] ? I : T, option: React.ReactElement) => void; + onSelect?: (value: T extends (infer I)[] ? I : T, option: React.ReactElement) => void; onDeselect?: (value: T extends (infer I)[] ? I : T) => void; onBlur?: (value: T) => void; onFocus?: () => void; @@ -75,7 +75,7 @@ export interface SelectProps extends AbstractSelectProps { optionFilterProp?: string; labelInValue?: boolean; tokenSeparators?: string[]; - getInputElement?: () => React.ReactElement; + getInputElement?: () => React.ReactElement; autoFocus?: boolean; suffixIcon?: React.ReactNode; removeIcon?: React.ReactNode; diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 103441fcd9..ed5eab8828 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -43,7 +43,7 @@ import warning from '../_util/warning'; function noop() {} -function stopPropagation(e: React.SyntheticEvent) { +function stopPropagation(e: React.SyntheticEvent) { e.stopPropagation(); if (e.nativeEvent.stopImmediatePropagation) { e.nativeEvent.stopImmediatePropagation(); diff --git a/components/table/filterDropdown.tsx b/components/table/filterDropdown.tsx index 5e35e5799c..07ea02a891 100755 --- a/components/table/filterDropdown.tsx +++ b/components/table/filterDropdown.tsx @@ -13,7 +13,7 @@ import FilterDropdownMenuWrapper from './FilterDropdownMenuWrapper'; import { FilterMenuProps, FilterMenuState, ColumnProps, ColumnFilterItem } from './interface'; import { generateValueMaps } from './util'; -function stopPropagation(e: React.SyntheticEvent) { +function stopPropagation(e: React.SyntheticEvent) { e.stopPropagation(); if (e.nativeEvent.stopImmediatePropagation) { e.nativeEvent.stopImmediatePropagation(); diff --git a/components/table/interface.tsx b/components/table/interface.tsx index 7b8d180715..653633f0e8 100644 --- a/components/table/interface.tsx +++ b/components/table/interface.tsx @@ -29,10 +29,10 @@ export interface ColumnProps { | ((options: { filters: TableStateFilters; sortOrder?: SortOrder }) => React.ReactNode); key?: React.Key; dataIndex?: string; // Note: We can not use generic type here, since we need to support nested key, see #9393 - render?: (text: unknown, record: T, index: number) => React.ReactNode; + render?: (text: any, record: T, index: number) => React.ReactNode; align?: 'left' | 'right' | 'center'; filters?: ColumnFilterItem[]; - onFilter?: (value: unknown, record: T) => boolean; + onFilter?: (value: any, record: T) => boolean; filterMultiple?: boolean; filterDropdown?: React.ReactNode | ((props: FilterDropdownProps) => React.ReactNode); filterDropdownVisible?: boolean; @@ -44,7 +44,7 @@ export interface ColumnProps { className?: string; fixed?: boolean | ('left' | 'right'); filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode); - filteredValue?: unknown[]; + filteredValue?: any[]; sortOrder?: SortOrder | boolean; children?: ColumnProps[]; onCellClick?: (record: T, event: Event) => void; @@ -219,7 +219,7 @@ export interface SelectionCheckboxAllProps { getRecordKey: (record: T, index?: number) => string; data: T[]; prefixCls: string | undefined; - onSelect: (key: string, index: number, selectFunc: unknown) => void; + onSelect: (key: string, index: number, selectFunc: any) => void; hideDefaultSelections?: boolean; selections?: SelectionItem[] | boolean; getPopupContainer?: GetPopupContainer; @@ -256,7 +256,7 @@ export interface FilterMenuProps { locale: TableLocale; selectedKeys: string[]; column: ColumnProps; - confirmFilter: (column: ColumnProps, selectedKeys: string[]) => unknown; + confirmFilter: (column: ColumnProps, selectedKeys: string[]) => any; prefixCls: string; dropdownPrefixCls: string; getPopupContainer?: GetPopupContainer; diff --git a/components/tabs/index.tsx b/components/tabs/index.tsx index 0c0a7acd7d..80972dad39 100755 --- a/components/tabs/index.tsx +++ b/components/tabs/index.tsx @@ -31,7 +31,7 @@ export interface TabsProps { className?: string; animated?: boolean | { inkBar: boolean; tabPane: boolean }; tabBarGutter?: number; - renderTabBar?: (props: TabsProps, DefaultTabBar: React.ReactNode) => React.ReactElement; + renderTabBar?: (props: TabsProps, DefaultTabBar: React.ReactNode) => React.ReactElement; destroyInactiveTabPane?: boolean; } diff --git a/components/tree-select/interface.tsx b/components/tree-select/interface.tsx index da9f58d90e..9484cb878f 100644 --- a/components/tree-select/interface.tsx +++ b/components/tree-select/interface.tsx @@ -35,16 +35,16 @@ export interface TreeSelectProps extends AbstractSelect autoFocus?: boolean; defaultValue?: T; dropdownStyle?: React.CSSProperties; - filterTreeNode?: (inputValue: string, treeNode: unknown) => boolean | boolean; + filterTreeNode?: (inputValue: string, treeNode: any) => boolean | boolean; labelInValue?: boolean; - loadData?: (node: unknown) => void; + loadData?: (node: any) => void; maxTagCount?: number; - maxTagPlaceholder?: React.ReactNode | ((omittedValues: unknown[]) => React.ReactNode); + maxTagPlaceholder?: React.ReactNode | ((omittedValues: any[]) => React.ReactNode); multiple?: boolean; notFoundContent?: React.ReactNode; - onChange?: (value: T, label: unknown, extra: unknown) => void; - onSearch?: (value: unknown) => void; - onSelect?: (value: unknown) => void; + onChange?: (value: T, label: any, extra: any) => void; + onSearch?: (value: any) => void; + onSelect?: (value: any) => void; onTreeExpand?: (keys: Array) => void; onFocus?: React.FocusEventHandler; onBlur?: React.FocusEventHandler; diff --git a/components/tree/Tree.tsx b/components/tree/Tree.tsx index 5d555119fc..92e8fe41ad 100644 --- a/components/tree/Tree.tsx +++ b/components/tree/Tree.tsx @@ -148,7 +148,7 @@ export interface TreeProps { style?: React.CSSProperties; showIcon?: boolean; icon?: ((nodeProps: AntdTreeNodeAttribute) => React.ReactNode) | React.ReactNode; - switcherIcon?: React.ReactElement; + switcherIcon?: React.ReactElement; prefixCls?: string; filterTreeNode?: (node: AntTreeNode) => boolean; children?: React.ReactNode; From c0bd255822509a81d958272e74a0d3e8e1196c80 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 24 Jun 2019 11:46:02 +0800 Subject: [PATCH 4/5] lock eslint-plugin-react for yannickcr/eslint-plugin-react#2319 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 13573f843e..5efbde2142 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "eslint-plugin-jest": "^22.6.4", "eslint-plugin-jsx-a11y": "^6.2.1", "eslint-plugin-markdown": "~1.0.0", - "eslint-plugin-react": "^7.13.0", + "eslint-plugin-react": "~7.13.0", "eslint-tinker": "^0.5.0", "fetch-jsonp": "^1.1.3", "glob": "^7.1.4", From 3f8589cff3b65888b80e8ccb4162088be189e92c Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 24 Jun 2019 11:49:55 +0800 Subject: [PATCH 5/5] chore: code style --- components/modal/Modal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index bdd32b1eae..7065776d76 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -214,7 +214,7 @@ export default class Modal extends React.Component { const closeIcon = ( - + );