Browse Source

Fix implicit any error for Calendar

pull/8292/head
Wei Zhu 7 years ago
parent
commit
f4dc69f5f0
  1. 14
      components/calendar/Header.tsx
  2. 28
      components/calendar/index.tsx

14
components/calendar/Header.tsx

@ -12,7 +12,7 @@ export interface HeaderProps {
yearSelectOffset?: number; yearSelectOffset?: number;
yearSelectTotal?: number; yearSelectTotal?: number;
type?: string; type?: string;
onValueChange?: (value) => void; onValueChange?: (value: moment.Moment) => void;
onTypeChange?: (type: string) => void; onTypeChange?: (type: string) => void;
value: any; value: any;
} }
@ -24,9 +24,9 @@ export default class Header extends React.Component<HeaderProps, any> {
yearSelectTotal: 20, yearSelectTotal: 20,
}; };
private calenderHeaderNode: any; private calenderHeaderNode: HTMLDivElement;
getYearSelectElement(year) { getYearSelectElement(year: number) {
const { yearSelectOffset, yearSelectTotal, locale, prefixCls, fullscreen } = this.props; const { yearSelectOffset, yearSelectTotal, locale, prefixCls, fullscreen } = this.props;
const start = year - (yearSelectOffset as number); const start = year - (yearSelectOffset as number);
const end = start + (yearSelectTotal as number); const end = start + (yearSelectTotal as number);
@ -61,7 +61,7 @@ export default class Header extends React.Component<HeaderProps, any> {
return months; return months;
} }
getMonthSelectElement(month, months) { getMonthSelectElement(month: number, months: number[]) {
const props = this.props; const props = this.props;
const { prefixCls, fullscreen } = props; const { prefixCls, fullscreen } = props;
const options: React.ReactElement<any>[] = []; const options: React.ReactElement<any>[] = [];
@ -84,7 +84,7 @@ export default class Header extends React.Component<HeaderProps, any> {
); );
} }
onYearChange = (year) => { onYearChange = (year: string) => {
const newValue = this.props.value.clone(); const newValue = this.props.value.clone();
newValue.year(parseInt(year, 10)); newValue.year(parseInt(year, 10));
@ -94,7 +94,7 @@ export default class Header extends React.Component<HeaderProps, any> {
} }
} }
onMonthChange = (month) => { onMonthChange = (month: string) => {
const newValue = this.props.value.clone(); const newValue = this.props.value.clone();
newValue.month(parseInt(month, 10)); newValue.month(parseInt(month, 10));
const onValueChange = this.props.onValueChange; const onValueChange = this.props.onValueChange;
@ -110,7 +110,7 @@ export default class Header extends React.Component<HeaderProps, any> {
} }
} }
getCalenderHeaderNode = (node) => { getCalenderHeaderNode = (node: HTMLDivElement) => {
this.calenderHeaderNode = node; this.calenderHeaderNode = node;
} }

28
components/calendar/index.tsx

@ -13,7 +13,7 @@ export { HeaderProps } from './Header';
function noop() { return null; } function noop() { return null; }
function zerofixed(v) { function zerofixed(v: number) {
if (v < 10) { if (v < 10) {
return `0${v}`; return `0${v}`;
} }
@ -41,7 +41,7 @@ export interface CalendarProps {
} }
export interface CalendarState { export interface CalendarState {
value?: moment.Moment; value: moment.Moment;
mode?: CalendarMode; mode?: CalendarMode;
} }
@ -70,8 +70,8 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
onSelect: PropTypes.func, onSelect: PropTypes.func,
}; };
constructor(props, context) { constructor(props: CalendarProps) {
super(props, context); super(props);
const value = props.value || props.defaultValue || callMoment(moment); const value = props.value || props.defaultValue || callMoment(moment);
if (!moment.isMoment(value)) { if (!moment.isMoment(value)) {
@ -89,12 +89,12 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
componentWillReceiveProps(nextProps: CalendarProps) { componentWillReceiveProps(nextProps: CalendarProps) {
if ('value' in nextProps) { if ('value' in nextProps) {
this.setState({ this.setState({
value: nextProps.value, value: nextProps.value!,
}); });
} }
} }
monthCellRender = (value) => { monthCellRender = (value: moment.Moment) => {
const { prefixCls, monthCellRender = noop as Function } = this.props; const { prefixCls, monthCellRender = noop as Function } = this.props;
return ( return (
<div className={`${prefixCls}-month`}> <div className={`${prefixCls}-month`}>
@ -108,7 +108,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
); );
} }
dateCellRender = (value) => { dateCellRender = (value: moment.Moment) => {
const { prefixCls, dateCellRender = noop as Function } = this.props; const { prefixCls, dateCellRender = noop as Function } = this.props;
return ( return (
<div className={`${prefixCls}-date`}> <div className={`${prefixCls}-date`}>
@ -127,7 +127,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
return locale.default || locale; return locale.default || locale;
} }
setValue = (value, way: 'select' | 'changePanel') => { setValue = (value: moment.Moment, way: 'select' | 'changePanel') => {
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ value }); this.setState({ value });
} }
@ -140,7 +140,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
} }
} }
setType = (type) => { setType = (type: string) => {
const mode = (type === 'date') ? 'month' : 'year'; const mode = (type === 'date') ? 'month' : 'year';
if (this.state.mode !== mode) { if (this.state.mode !== mode) {
this.setState({ mode }); this.setState({ mode });
@ -148,26 +148,26 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
} }
} }
onHeaderValueChange = (value) => { onHeaderValueChange = (value: moment.Moment) => {
this.setValue(value, 'changePanel'); this.setValue(value, 'changePanel');
} }
onHeaderTypeChange = (type) => { onHeaderTypeChange = (type: string) => {
this.setType(type); this.setType(type);
} }
onPanelChange(value, mode) { onPanelChange(value: moment.Moment, mode: CalendarMode | undefined) {
const { onPanelChange } = this.props; const { onPanelChange } = this.props;
if (onPanelChange) { if (onPanelChange) {
onPanelChange(value, mode); onPanelChange(value, mode);
} }
} }
onSelect = (value) => { onSelect = (value: moment.Moment) => {
this.setValue(value, 'select'); this.setValue(value, 'select');
} }
renderCalendar = (locale, localeCode) => { renderCalendar = (locale: any, localeCode: string) => {
const { state, props } = this; const { state, props } = this;
const { value, mode } = state; const { value, mode } = state;
if (value && localeCode) { if (value && localeCode) {

Loading…
Cancel
Save