Skip to content

Commit

Permalink
Fix implicit any error for DatePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Nov 21, 2017
1 parent 93fcbdf commit 9fd3588
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
20 changes: 10 additions & 10 deletions components/date-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function pickerValueAdapter(value?: moment.Moment | moment.Moment[]): moment.Mom
return [value, value.clone().add(1, 'month')];
}

function isEmptyArray(arr) {
function isEmptyArray(arr: any) {
if (Array.isArray(arr)) {
return arr.length === 0 || arr.every(i => !i);
}
Expand All @@ -46,7 +46,7 @@ export default class RangePicker extends React.Component<any, any> {
showToday: false,
};

constructor(props) {
constructor(props: any) {
super(props);
const value = props.value || props.defaultValue || [];
if (
Expand All @@ -67,7 +67,7 @@ export default class RangePicker extends React.Component<any, any> {
};
}

componentWillReceiveProps(nextProps) {
componentWillReceiveProps(nextProps: any) {
if ('value' in nextProps) {
const state = this.state;
const value = nextProps.value || [];
Expand All @@ -83,7 +83,7 @@ export default class RangePicker extends React.Component<any, any> {
}
}

clearSelection = (e) => {
clearSelection = (e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
this.setState({ value: [] });
Expand All @@ -106,7 +106,7 @@ export default class RangePicker extends React.Component<any, any> {
]);
}

handleOpenChange = (open) => {
handleOpenChange = (open: boolean) => {
if (!('open' in this.props)) {
this.setState({ open });
}
Expand All @@ -117,18 +117,18 @@ export default class RangePicker extends React.Component<any, any> {
}
}

handleShowDateChange = showDate => this.setState({ showDate });
handleShowDateChange = (showDate: boolean) => this.setState({ showDate });

handleHoverChange = hoverValue => this.setState({ hoverValue });
handleHoverChange = (hoverValue: any) => this.setState({ hoverValue });

setValue(value, hidePanel?) {
setValue(value: moment.Moment[], hidePanel?: boolean) {
this.handleChange(value);
if ((hidePanel || !this.props.showTime) && !('open' in this.props)) {
this.setState({ open: false });
}
}

renderFooter = (...args) => {
renderFooter = (...args: any[]) => {
const { prefixCls, ranges, renderExtraFooter } = this.props;
if (!ranges && !renderExtraFooter) {
return null;
Expand Down Expand Up @@ -243,7 +243,7 @@ export default class RangePicker extends React.Component<any, any> {
/>
) : null;

const input = ({ value: inputValue }) => {
const input = ({ value: inputValue }: { value: any }) => {
const start = inputValue[0];
const end = inputValue[1];
return (
Expand Down
14 changes: 7 additions & 7 deletions components/date-picker/WeekPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import RcDatePicker from 'rc-calendar/lib/Picker';
import classNames from 'classnames';
import Icon from '../icon';

function formatValue(value: moment.Moment | undefined, format: string): string {
function formatValue(value: moment.Moment | null, format: string): string {
return (value && value.format(format)) || '';
}

Expand All @@ -14,7 +14,7 @@ export default class WeekPicker extends React.Component<any, any> {
format: 'YYYY-Wo',
allowClear: true,
};
constructor(props) {
constructor(props: any) {
super(props);
const value = props.value || props.defaultValue;
if (value && !moment.isMoment(value)) {
Expand All @@ -27,12 +27,12 @@ export default class WeekPicker extends React.Component<any, any> {
value,
};
}
componentWillReceiveProps(nextProps) {
componentWillReceiveProps(nextProps: any) {
if ('value' in nextProps) {
this.setState({ value: nextProps.value });
}
}
weekDateRender = (current) => {
weekDateRender = (current: any) => {
const selectedValue = this.state.value;
const { prefixCls } = this.props;
if (selectedValue &&
Expand All @@ -52,13 +52,13 @@ export default class WeekPicker extends React.Component<any, any> {
</div>
);
}
handleChange = (value) => {
handleChange = (value: moment.Moment | null) => {
if (!('value' in this.props)) {
this.setState({ value });
}
this.props.onChange(value, formatValue(value, this.props.format));
}
clearSelection = (e) => {
clearSelection = (e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
this.handleChange(null);
Expand Down Expand Up @@ -96,7 +96,7 @@ export default class WeekPicker extends React.Component<any, any> {
onClick={this.clearSelection}
/>
) : null;
const input = ({ value }) => {
const input = ({ value }: { value: moment.Moment | undefined }) => {
return (
<span>
<input
Expand Down
12 changes: 6 additions & 6 deletions components/date-picker/createPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export interface PickerProps {
prefixCls: string;
}

export default function createPicker(TheCalendar): any {
export default function createPicker(TheCalendar: React.ComponentClass): any {
return class CalenderWrapper extends React.Component<any, any> {
static defaultProps = {
prefixCls: 'ant-calendar',
allowClear: true,
showToday: true,
};

constructor(props) {
constructor(props: any) {
super(props);
const value = props.value || props.defaultValue;
if (value && !moment.isMoment(value)) {
Expand All @@ -43,7 +43,7 @@ export default function createPicker(TheCalendar): any {
}
}

renderFooter = (...args) => {
renderFooter = (...args: any[]) => {
const { prefixCls, renderExtraFooter } = this.props;
return renderExtraFooter ? (
<div className={`${prefixCls}-footer-extra`}>
Expand All @@ -52,13 +52,13 @@ export default function createPicker(TheCalendar): any {
) : null;
}

clearSelection = (e) => {
clearSelection = (e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
this.handleChange(null);
}

handleChange = (value) => {
handleChange = (value: moment.Moment | null) => {
const props = this.props;
if (!('value' in props)) {
this.setState({ value });
Expand Down Expand Up @@ -127,7 +127,7 @@ export default function createPicker(TheCalendar): any {
/>
) : null;

const input = ({ value: inputValue }) => (
const input = ({ value: inputValue }: { value: moment.Moment | null }) => (
<div>
<input
disabled={props.disabled}
Expand Down
8 changes: 4 additions & 4 deletions components/date-picker/wrapPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { generateShowHourMinuteSecond } from '../time-picker';
import warning from '../_util/warning';
declare const require: Function;

function getColumns({ showHour, showMinute, showSecond, use12Hours }) {
function getColumns({ showHour, showMinute, showSecond, use12Hours }: any) {
let column = 0;
if (showHour) {
column += 1;
Expand All @@ -23,7 +23,7 @@ function getColumns({ showHour, showMinute, showSecond, use12Hours }) {
return column;
}

export default function wrapPicker(Picker, defaultFormat?: string): any {
export default function wrapPicker(Picker: React.ComponentClass<any>, defaultFormat?: string): any {
return class PickerWrapper extends React.Component<any, any> {
static defaultProps = {
format: defaultFormat || 'YYYY-MM-DD',
Expand All @@ -40,7 +40,7 @@ export default function wrapPicker(Picker, defaultFormat?: string): any {
inputPrefixCls: 'ant-input',
};

handleOpenChange = (open) => {
handleOpenChange = (open: boolean) => {
const { onOpenChange, toggleOpen } = this.props;
onOpenChange(open);

Expand All @@ -59,7 +59,7 @@ export default function wrapPicker(Picker, defaultFormat?: string): any {
return locale.default || locale;
}

renderPicker = (locale, localeCode) => {
renderPicker = (locale: any, localeCode: string) => {
const props = this.props;
const { prefixCls, inputPrefixCls } = props;
const pickerClass = classNames(`${prefixCls}-picker`, {
Expand Down

0 comments on commit 9fd3588

Please sign in to comment.