Skip to content

Commit

Permalink
fix: some tsc errors (ant-design#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui authored and afc163 committed Aug 22, 2016
1 parent 5d39bd9 commit 5dcce12
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 57 deletions.
2 changes: 1 addition & 1 deletion components/auto-complete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Select, { Option, OptGroup } from '../select';
import classNames from 'classnames';

export interface AutoCompleteProps {
size?: string;
size?: 'large' | 'small' | 'default';
className?: string;
notFoundContent?: Element;
dataSource: Array<any>;
Expand Down
1 change: 1 addition & 0 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface ButtonProps {
shape?: ButtonShape;
size?: ButtonSize;
onClick?: React.FormEventHandler;
onMouseUp?: React.FormEventHandler;
loading?: boolean;
disabled?: boolean;
style?: React.CSSProperties;
Expand Down
3 changes: 2 additions & 1 deletion components/calendar/locale/en_US.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('../../date-picker/locale/en_US');
import en_US from '../../date-picker/locale/en_US';
export default en_US;
3 changes: 2 additions & 1 deletion components/calendar/locale/ru_RU.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('../../date-picker/locale/ru_RU');
import ru_RU from '../../date-picker/locale/ru_RU';
export default ru_RU;
3 changes: 2 additions & 1 deletion components/calendar/locale/zh_CN.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('../../date-picker/locale/zh_CN');
import zh_CN from '../../date-picker/locale/zh_CN';
export default zh_CN;
5 changes: 3 additions & 2 deletions components/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// https://github.com/WickyNilliams/enquire.js/issues/82
import assign from 'object-assign';
if (typeof window !== 'undefined') {
const matchMediaPolyfill = function matchMediaPolyfill() {
const matchMediaPolyfill = function matchMediaPolyfill(mediaQuery: string): MediaQueryList {
return {
media: mediaQuery,
matches: false,
addListener() {
},
Expand All @@ -23,7 +24,7 @@ export interface CarouselProps {
/** 动画效果函数,可取 scrollx, fade */
effect?: CarouselEffect;
/** 是否显示面板指示点 */
dots?: SlickCarouselboolean;
dots?: boolean;
/** 垂直显示 */
vertical?: boolean;
/** 是否自动切换 */
Expand Down
1 change: 1 addition & 0 deletions components/checkbox/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class CheckboxGroup extends React.Component<CheckboxGroupProps, C
}
getOptions() {
const { options } = this.props;
// https://github.com/Microsoft/TypeScript/issues/7960
return options.map(option => {
if (typeof option === 'string') {
return {
Expand Down
6 changes: 3 additions & 3 deletions components/date-picker/createPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export default function createPicker(TheCalendar) {
});

// 需要选择时间时,点击 ok 时才触发 onChange
let pickerChangeHandler = {
let pickerChangeHandler: Object = {
onChange: this.handleChange,
};
let calendarHandler = {
let calendarHandler: Object = {
onOk: this.handleChange,
// fix https://github.com/ant-design/ant-design/issues/1902
onSelect: (value, cause) => {
Expand Down Expand Up @@ -95,7 +95,7 @@ export default function createPicker(TheCalendar) {
);

// default width for showTime
const pickerStyle = {};
const pickerStyle = { width: undefined };
if (props.showTime) {
pickerStyle.width = 180;
}
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/wrapPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function wrapPicker(Picker, defaultFormat?) {

getFormatter() {
const format = this.props.format;
const formatter = new DateTimeFormat(format, this.getLocale().lang.format);
const formatter = new DateTimeFormat(format as string, this.getLocale().lang.format);
return formatter;
},

Expand Down
28 changes: 14 additions & 14 deletions components/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ export interface FormProps {
}

// function create
export type CreateFormOptions = {
export type WrappedFormUtils = {
/** 获取一组输入控件的值,如不传入参数,则获取全部组件的值*/
getFieldsValue(): (fieldNames?: Array<string>) => any;
getFieldsValue(fieldNames?: Array<string>): Object;
/** 获取一个输入控件的值*/
getFieldValue(): (fieldName: string) => any;
getFieldValue(fieldName: string): any;
/** 设置一组输入控件的值*/
setFieldsValue(): (obj: Object) => void;
setFieldsValue(obj: Object): void;
/** 设置一组输入控件的值*/
setFields(): (obj: Object) => void;
setFields(obj: Object): void;
/** 校验并获取一组输入域的值与 Error*/
validateFields(): (fieldNames?: Array<string>, options?: Object, callback?: (erros: any, values: any) => void) => any;
validateFields(fieldNames?: Array<string>, options?: Object, callback?: (erros: any, values: any) => void): any;
/** 与 `validateFields` 相似,但校验完后,如果校验不通过的菜单域不在可见范围内,则自动滚动进可见范围 */
validateFieldsAndScroll(): (
validateFieldsAndScroll(
fieldNames?: Array<string>,
options?: Object,
callback?: (erros: any, values: any) => void
) => any;
): void;
/** 获取某个输入控件的 Error */
getFieldError(): (name: string) => Object;
getFieldError(name: string): Object[];
/** 判断一个输入控件是否在校验状态*/
isFieldValidating(): (name: string) => Object;
isFieldValidating(name: string): boolean;
/**重置一组输入控件的值与状态,如不传入参数,则重置所有组件*/
resetFields(): (names?: Array<string>) => void;
resetFields(names?: Array<string>): void;

getFieldsValue(): (id: string, options: {
getFieldProps(id: string, options: {
/** 子节点的值的属性,如 Checkbox 的是 'checked'*/
valuePropName?: string;
/** 子节点的初始值,类型、可选值均由子节点决定*/
Expand All @@ -65,11 +65,11 @@ export type CreateFormOptions = {
rules?: Array<any>;
/** 必填输入控件唯一标志*/
id?: string;
}) => Array<any>;
}): Array<any>;
}

export interface FormComponentProps {
form: CreateFormOptions;
form: WrappedFormUtils;
}

export class FormComponent extends React.Component<FormComponentProps, {}> {
Expand Down
13 changes: 11 additions & 2 deletions components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classNames from 'classnames';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import Row from '../row';
import Col from '../col';
import { WrappedFormUtils } from './Form';
import { FIELD_META_PROP } from './constants';

export interface FormItemLabelColOption {
Expand All @@ -12,7 +13,8 @@ export interface FormItemLabelColOption {

export interface FormItemProps {
prefixCls?: string;
label?: React.ReactNode;
id?: string;
label?: string;
labelCol?: FormItemLabelColOption;
wrapperCol?: FormItemLabelColOption;
help?: React.ReactNode;
Expand All @@ -22,6 +24,11 @@ export interface FormItemProps {
className?: string;
required?: boolean;
style?: React.CSSProperties;
colon?: boolean;
}

export interface FormItemContext {
form: WrappedFormUtils;
}

export default class FormItem extends React.Component<FormItemProps, any> {
Expand All @@ -33,7 +40,7 @@ export default class FormItem extends React.Component<FormItemProps, any> {

static propTypes = {
prefixCls: React.PropTypes.string,
label: React.PropTypes.node,
label: React.PropTypes.string,
labelCol: React.PropTypes.object,
help: React.PropTypes.oneOfType([React.PropTypes.node, React.PropTypes.bool]),
validateStatus: React.PropTypes.oneOf(['', 'success', 'warning', 'error', 'validating']),
Expand All @@ -49,6 +56,8 @@ export default class FormItem extends React.Component<FormItemProps, any> {
form: React.PropTypes.object,
};

context: FormItemContext;

shouldComponentUpdate(...args) {
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
}
Expand Down
3 changes: 2 additions & 1 deletion components/form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react';
import * as React from 'react';
import { PropTypes } from 'react';
import createDOMForm from 'rc-form/lib/createDOMForm';
import Form from './Form';
import FormItem from './FormItem';
Expand Down
1 change: 1 addition & 0 deletions components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
export interface IconProps {
type: string;
className?: string;
title?: string;
onClick?: (e) => void;
}

Expand Down
8 changes: 5 additions & 3 deletions components/input/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as React from 'react';
import classNames from 'classnames';

export interface GroupProps {
size?: 'large' | 'small' | 'default';
className?: string;
size?: 'large' | 'small' | 'default';
children?: any;
style?: React.CSSProperties;
}

export default function Group(props: GroupProps) {
const Group: React.StatelessComponent<GroupProps> = (props) => {
const className = classNames({
'ant-input-group': true,
'ant-input-group-lg': props.size === 'large',
Expand All @@ -20,8 +20,10 @@ export default function Group(props: GroupProps) {
{props.children}
</span>
);
}
};

Group.propTypes = {
children: React.PropTypes.any,
};

export default Group;
14 changes: 9 additions & 5 deletions components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ interface AutoSizeType {

export interface InputProps {
prefixCls?: string;
className?: string;
type: string;
id?: number | string;
value?: any;
defaultValue?: any;
placeholder?: string;
size?: 'large' | 'default' | 'small';
disabled?: boolean;
readOnly?: boolean;
addonBefore?: React.ReactNode;
addonAfter?: React.ReactNode;
onPressEnter?: (e) => any;
onKeyDown?: (e) => any;
onChange?: (e) => any;
onPressEnter?: React.FormEventHandler;
onKeyDown?: React.FormEventHandler;
onChange?: React.FormEventHandler;
autosize?: boolean | AutoSizeType;
}

export default class Input extends Component<InputProps, any> {
static Group: any;
static defaultProps = {
defaultValue: '',
disabled: false,
Expand Down Expand Up @@ -121,8 +125,8 @@ export default class Input extends Component<InputProps, any> {
if (type !== 'textarea' || !autosize || !this.refs.input) {
return;
}
const minRows = autosize ? autosize.minRows : null;
const maxRows = autosize ? autosize.maxRows : null;
const minRows = autosize ? (autosize as AutoSizeType).minRows : null;
const maxRows = autosize ? (autosize as AutoSizeType).maxRows : null;
const textareaStyles = calculateNodeHeight(this.refs.input, false, minRows, maxRows);
this.setState({ textareaStyles });
}
Expand Down
4 changes: 2 additions & 2 deletions components/input/demo/search-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ title:
en-US: Search box
---

## zh-CN:
## zh-CN

带有搜索按钮的输入框。

## en-US:
## en-US

Example of creating a search box by grouping a standard input with a search button.

Expand Down
12 changes: 8 additions & 4 deletions components/layout/col.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { PropTypes } from 'react';
import * as React from 'react';
import { PropTypes } from 'react';
import classNames from 'classnames';
import assign from 'object-assign';
import splitObject from '../_util/splitObject';

const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
const objectOrNumber = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);
import splitObject from '../_util/splitObject';

interface ColSize {
span?: number;
Expand All @@ -15,6 +16,7 @@ interface ColSize {
}

export interface ColProps {
className?: string;
span?: number;
order?: number;
offset?: number;
Expand All @@ -26,7 +28,7 @@ export interface ColProps {
lg?: ColSize;
}

export default function Col(props: ColProps) {
const Col: React.StatelessComponent<ColProps> = (props) => {
const [{ span, order, offset, push, pull, className, children }, others] = splitObject(props,
['span', 'order', 'offset', 'push', 'pull', 'className', 'children']);
let sizeClassObj = {};
Expand Down Expand Up @@ -58,7 +60,7 @@ export default function Col(props: ColProps) {
}, sizeClassObj));

return <div {...others} className={classes}>{children}</div>;
}
};

Col.propTypes = {
span: stringOrNumber,
Expand All @@ -73,3 +75,5 @@ Col.propTypes = {
md: objectOrNumber,
lg: objectOrNumber,
};

export default Col;
4 changes: 3 additions & 1 deletion components/layout/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import assign from 'object-assign';
import splitObject from '../_util/splitObject';

export interface RowProps {
className?: string;
gutter?: number;
type?: 'flex';
align?: 'top' | 'middle' | 'bottom';
justify?: 'start' | 'end' | 'center' | 'space-around' | 'space-between';
style?: React.CSSProperties;
}

export default class Row extends React.Component<RowProps, any> {
Expand Down Expand Up @@ -37,7 +39,7 @@ export default class Row extends React.Component<RowProps, any> {
marginLeft: gutter / -2,
marginRight: gutter / -2,
}, style) : style;
const cols = Children.map(children, col => {
const cols = Children.map(children, (col) => {
if (!col) {
return null;
}
Expand Down
7 changes: 6 additions & 1 deletion components/modal/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import classNames from 'classnames';
import { getConfirmLocale } from './locale';
import assign from 'object-assign';

class ActionButton extends React.Component {
export interface ActionButtonProps {
type: 'primary' | 'ghost' | 'dashed';
actionFn: Function;
closeModal: Function;
}
class ActionButton extends React.Component<ActionButtonProps, any> {
constructor(props) {
super(props);
this.state = {
Expand Down
3 changes: 2 additions & 1 deletion components/pagination/locale/en_US.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('rc-pagination/lib/locale/en_US');
import en_US from 'rc-pagination/lib/locale/en_US';
export default en_US;
3 changes: 2 additions & 1 deletion components/pagination/locale/zh_CN.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('rc-pagination/lib/locale/zh_CN');
import zh_CN from 'rc-pagination/lib/locale/zh_CN';
export default zh_CN;
2 changes: 2 additions & 0 deletions components/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface SelectContext {
};
}

export { Option, OptGroup }

export default class Select extends React.Component<SelectProps, any> {
static Option = Option;
static OptGroup = OptGroup;
Expand Down
Loading

0 comments on commit 5dcce12

Please sign in to comment.