Skip to content

Commit

Permalink
eliminate any type in exported interfaces.ant-design#14044
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzzen committed Jun 16, 2019
1 parent cb4a86a commit f1ee189
Show file tree
Hide file tree
Showing 49 changed files with 217 additions and 190 deletions.
1 change: 1 addition & 0 deletions components/_util/interopDefault.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion components/anchor/AnchorLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface AnchorLinkProps {
prefixCls?: string;
href: string;
title: React.ReactNode;
children?: any;
children?: React.ReactNode;
className?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion components/auto-complete/InputElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';

export interface InputElementProps {
children: React.ReactElement<any>;
children: React.ReactElement<unknown>;
}

export default class InputElement extends React.Component<InputElementProps, any> {
Expand Down
6 changes: 3 additions & 3 deletions components/auto-complete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type DataSourceItemType =
| React.ReactElement<OptGroupProps>;

export interface AutoCompleteInputProps {
onChange?: React.FormEventHandler<any>;
value: any;
onChange?: React.FormEventHandler<unknown>;
value: unknown;
}

export type ValidInputElement =
Expand All @@ -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?:
Expand Down
2 changes: 1 addition & 1 deletion components/avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down
2 changes: 1 addition & 1 deletion components/back-top/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getDefaultTarget() {

export interface BackTopProps {
visibilityHeight?: number;
onClick?: React.MouseEventHandler<any>;
onClick?: React.MouseEventHandler<HTMLElement>;
target?: () => HTMLElement | Window;
prefixCls?: string;
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion components/badge/ScrollNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ScrollNumberProps {
prefixCls?: string;
className?: string;
count?: string | number | null;
displayComponent?: React.ReactElement<any>;
displayComponent?: React.ReactElement<HTMLElement>;
component?: string;
onAnimated?: Function;
style?: React.CSSProperties;
Expand Down
34 changes: 16 additions & 18 deletions components/breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>,
route: Route,
params: unknown,
routes: Array<Route>,
paths: Array<string>,
) => React.ReactNode;
style?: React.CSSProperties;
Expand Down Expand Up @@ -72,21 +72,21 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
}

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 = [],
Expand All @@ -107,12 +107,10 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
overlay = (
<Menu>
{route.children.map(child => (
<Menu.Item key={child.breadcrumbName || child.path}>
{
itemRender(child, params, routes, this.addChildPath(paths, child.path, params))
}
</Menu.Item>
))}
<Menu.Item key={child.breadcrumbName || child.path}>
{itemRender(child, params, routes, this.addChildPath(paths, child.path, params))}
</Menu.Item>
))}
</Menu>
);
}
Expand Down
10 changes: 5 additions & 5 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export interface BaseButtonProps {
export type AnchorButtonProps = {
href: string;
target?: string;
onClick?: React.MouseEventHandler<any>;
onClick?: React.MouseEventHandler<HTMLElement>;
} & BaseButtonProps &
Omit<React.AnchorHTMLAttributes<any>, 'type'>;
Omit<React.AnchorHTMLAttributes<unknown>, 'type' | 'onClick'>;

export type NativeButtonProps = {
htmlType?: ButtonHTMLType;
onClick?: React.MouseEventHandler<any>;
onClick?: React.MouseEventHandler<HTMLElement>;
} & BaseButtonProps &
Omit<React.ButtonHTMLAttributes<any>, 'type'>;
Omit<React.ButtonHTMLAttributes<unknown>, 'type' | 'onClick'>;

export type ButtonProps = Partial<AnchorButtonProps & NativeButtonProps>;

Expand Down Expand Up @@ -289,7 +289,7 @@ class Button extends React.Component<ButtonProps, ButtonState> {

const buttonNode = (
<button
{...otherProps as NativeButtonProps}
{...(otherProps as NativeButtonProps)}
type={htmlType}
className={classes}
onClick={this.handleClick}
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class Header extends React.Component<HeaderProps, any> {
};

onInternalTypeChange = (e: RadioChangeEvent) => {
this.onTypeChange(e.target.value);
this.onTypeChange(e.target.value as string);
};

onTypeChange = (type: string) => {
Expand Down
12 changes: 6 additions & 6 deletions components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export interface AbstractCheckboxProps<T> {
style?: React.CSSProperties;
disabled?: boolean;
onChange?: (e: T) => void;
onClick?: React.MouseEventHandler<any>;
onMouseEnter?: React.MouseEventHandler<any>;
onMouseLeave?: React.MouseEventHandler<any>;
onKeyPress?: React.KeyboardEventHandler<any>;
onKeyDown?: React.KeyboardEventHandler<any>;
value?: any;
onClick?: React.MouseEventHandler<HTMLElement>;
onMouseEnter?: React.MouseEventHandler<HTMLElement>;
onMouseLeave?: React.MouseEventHandler<HTMLElement>;
onKeyPress?: React.KeyboardEventHandler<HTMLElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLElement>;
value?: unknown;
tabIndex?: number;
name?: string;
children?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion components/checkbox/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface CheckboxGroupState {
export interface CheckboxGroupContext {
checkboxGroup: {
toggleOption: (option: CheckboxOptionType) => void;
value: any;
value: unknown;
disabled: boolean;
};
}
Expand Down
2 changes: 1 addition & 1 deletion components/collapse/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface CollapseProps {
className?: string;
bordered?: boolean;
prefixCls?: string;
expandIcon?: (panelProps: any) => React.ReactNode;
expandIcon?: (panelProps: PanelProps) => React.ReactNode;
expandIconPosition?: ExpandIconPosition;
}

Expand Down
2 changes: 1 addition & 1 deletion components/comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface CommentProps {
/** The main content of the comment */
content: React.ReactNode;
/** Nested comments should be provided as children of the Comment */
children?: any;
children?: React.ReactNode;
/** Comment prefix defaults to '.ant-comment' */
prefixCls?: string;
/** Additional style for the comment */
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/InputIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import Icon from '../icon';
import classNames from 'classnames';

export default function InputIcon(props: { suffixIcon: any; prefixCls: string }) {
export default function InputIcon(props: { suffixIcon: React.ReactNode; prefixCls: string }) {
const { suffixIcon, prefixCls } = props;
return (
(suffixIcon &&
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface PickerProps {
style?: React.CSSProperties;
popupStyle?: React.CSSProperties;
dropdownClassName?: string;
locale?: any;
locale?: unknown;
size?: 'large' | 'small' | 'default';
getCalendarContainer?: (triggerNode: Element) => HTMLElement;
open?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion components/dropdown/dropdown-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface DropdownButtonProps extends ButtonGroupProps, DropDownProps {
*/
icon?: React.ReactNode;
href?: string;
children?: any;
children?: React.ReactNode;
}

export default class DropdownButton extends React.Component<DropdownButtonProps, any> {
Expand Down
42 changes: 25 additions & 17 deletions components/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { FIELD_META_PROP, FIELD_DATA_PROP } from './constants';
import { FormContext } from './context';
import { FormWrappedProps } from './interface';

type FormCreateOptionMessagesCallback = (...args: any[]) => string;
type FormCreateOptionMessagesCallback = (...args: unknown[]) => string;

interface FormCreateOptionMessages {
[messageId: string]: string | FormCreateOptionMessagesCallback | FormCreateOptionMessages;
}

export interface FormCreateOption<T> {
onFieldsChange?: (props: T, fields: any, allFields: any) => void;
onValuesChange?: (props: T, changedValues: any, allValues: any) => void;
onFieldsChange?: (props: T, fields: unknown, allFields: unknown) => void;
onValuesChange?: (props: T, changedValues: unknown, allValues: unknown) => void;
mapPropsToFields?: (props: T) => void;
validateMessages?: FormCreateOptionMessages;
withRef?: boolean;
Expand All @@ -34,7 +34,7 @@ export type FormLayout = (typeof FormLayouts)[number];
export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
layout?: FormLayout;
form?: WrappedFormUtils;
onSubmit?: React.FormEventHandler<any>;
onSubmit?: React.FormEventHandler<HTMLElement>;
style?: React.CSSProperties;
className?: string;
prefixCls?: string;
Expand Down Expand Up @@ -71,32 +71,38 @@ export type ValidationRule = {
/** validate from a regular expression */
pattern?: RegExp;
/** transform a value before validation */
transform?: (value: any) => any;
transform?: (value: unknown) => unknown;
/** custom validate function (Note: callback must be called) */
validator?: (rule: any, value: any, callback: any, source?: any, options?: any) => any;
validator?: (
rule: unknown,
value: unknown,
callback: unknown,
source?: unknown,
options?: unknown,
) => unknown;
};

export type ValidateCallback<V> = (errors: any, values: V) => void;
export type ValidateCallback<V> = (errors: unknown, values: V) => void;

export type GetFieldDecoratorOptions = {
/** 子节点的值的属性,如 Checkbox 的是 'checked' */
valuePropName?: string;
/** 子节点的初始值,类型、可选值均由子节点决定 */
initialValue?: any;
initialValue?: unknown;
/** 收集子节点的值的时机 */
trigger?: string;
/** 可以把 onChange 的参数转化为控件的值,例如 DatePicker 可设为:(date, dateString) => dateString */
getValueFromEvent?: (...args: any[]) => any;
getValueFromEvent?: (...args: unknown[]) => unknown;
/** Get the component props according to field value. */
getValueProps?: (value: any) => any;
getValueProps?: (value: unknown) => unknown;
/** 校验子节点值的时机 */
validateTrigger?: string | string[];
/** 校验规则,参见 [async-validator](https://github.com/yiminghe/async-validator) */
rules?: ValidationRule[];
/** 是否和其他控件互斥,特别用于 Radio 单选控件 */
exclusive?: boolean;
/** Normalize value to form component */
normalize?: (value: any, prevValue: any, allValues: any) => any;
normalize?: (value: unknown, prevValue: unknown, allValues: unknown) => unknown;
/** Whether stop validate on first rule of error for this field. */
validateFirst?: boolean;
/** 是否一直保留子节点的信息 */
Expand Down Expand Up @@ -135,11 +141,11 @@ export type ValidateFieldsOptions = {
};

// function create
export type WrappedFormUtils<V = any> = {
export type WrappedFormUtils<V = unknown> = {
/** 获取一组输入控件的值,如不传入参数,则获取全部组件的值 */
getFieldsValue(fieldNames?: Array<string>): { [field: string]: any };
getFieldsValue(fieldNames?: Array<string>): { [field: string]: unknown };
/** 获取一个输入控件的值 */
getFieldValue(fieldName: string): any;
getFieldValue(fieldName: string): unknown;
/** 设置一组输入控件的值 */
setFieldsValue(obj: Object): void;
/** 设置一组输入控件的值 */
Expand Down Expand Up @@ -186,15 +192,17 @@ export type WrappedFormUtils<V = any> = {
): (node: React.ReactNode) => React.ReactNode;
};

export interface WrappedFormInternalProps<V = any> {
export interface WrappedFormInternalProps<V = unknown> {
form: WrappedFormUtils<V>;
}

export interface RcBaseFormProps {
wrappedComponentRef?: any;
wrappedComponentRef?: unknown;
}

export interface FormComponentProps<V = any> extends WrappedFormInternalProps<V>, RcBaseFormProps {
export interface FormComponentProps<V = unknown>
extends WrappedFormInternalProps<V>,
RcBaseFormProps {
form: WrappedFormUtils<V>;
}

Expand Down
2 changes: 1 addition & 1 deletion components/icon/IconFont.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customCache = new Set<string>();

export interface CustomIconOptions {
scriptUrl?: string;
extraCommonProps?: { [key: string]: any };
extraCommonProps?: { [key: string]: unknown };
}

export default function create(options: CustomIconOptions = {}): React.SFC<IconProps> {
Expand Down
2 changes: 1 addition & 1 deletion components/input/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
export interface GroupProps {
className?: string;
size?: 'large' | 'small' | 'default';
children?: any;
children?: React.ReactNode;
style?: React.CSSProperties;
onMouseEnter?: React.MouseEventHandler<HTMLSpanElement>;
onMouseLeave?: React.MouseEventHandler<HTMLSpanElement>;
Expand Down
2 changes: 1 addition & 1 deletion components/input/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface SearchProps extends InputProps {
onSearch?: (
value: string,
event?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLInputElement>,
) => any;
) => void;
enterButton?: boolean | React.ReactNode;
}

Expand Down
2 changes: 1 addition & 1 deletion components/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface ListProps<T> {
loadMore?: React.ReactNode;
pagination?: PaginationConfig | false;
prefixCls?: string;
rowKey?: any;
rowKey?: ((item: T) => string) | string;
renderItem?: (item: T, index: number) => React.ReactNode;
size?: ListSize;
split?: boolean;
Expand Down
Loading

0 comments on commit f1ee189

Please sign in to comment.