Fix implicit any error for List

This commit is contained in:
Wei Zhu 2017-11-21 19:02:04 +08:00
parent 084b444252
commit e7042ae541
2 changed files with 22 additions and 16 deletions

View File

@ -2,7 +2,7 @@ import * as React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { Col } from '../grid'; import { Col } from '../grid';
import { ListGridType } from './index'; import { ListGridType, ColumnType } from './index';
export interface ListItemProps { export interface ListItemProps {
className?: string; className?: string;
@ -51,8 +51,8 @@ export const Meta = (props: ListItemMetaProps) => {
); );
}; };
function getGrid(grid, t) { function getGrid(grid: ListGridType, t: ColumnType) {
return grid[t] && Math.floor(24 / grid[t]); return grid[t] && Math.floor(24 / grid[t]!);
} }
const GridColumns = ['', 1, 2, 3, 4, 6, 8, 12, 24]; const GridColumns = ['', 1, 2, 3, 4, 6, 8, 12, 24];
@ -99,7 +99,7 @@ export default class Item extends React.Component<ListItemProps, any> {
let actionsContent; let actionsContent;
if (actions && actions.length > 0) { if (actions && actions.length > 0) {
const actionsContentItem = (action, i) => ( const actionsContentItem = (action: React.ReactNode, i: number) => (
<li key={`${prefixCls}-item-action-${i}`}> <li key={`${prefixCls}-item-action-${i}`}>
{action} {action}
{i !== (actions.length - 1) && <em className={`${prefixCls}-item-action-split`}/>} {i !== (actions.length - 1) && <em className={`${prefixCls}-item-action-split`}/>}

View File

@ -12,16 +12,18 @@ import Item from './Item';
export { ListItemProps, ListItemMetaProps } from './Item'; export { ListItemProps, ListItemMetaProps } from './Item';
export type ColumnType = 1 | 2 | 3 | 4 | 6 | 8 | 12 | 24; export type ColumnCount = 1 | 2 | 3 | 4 | 6 | 8 | 12 | 24;
export type ColumnType = 'gutter' | 'column' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
export interface ListGridType { export interface ListGridType {
gutter?: number; gutter?: number;
column?: ColumnType; column?: ColumnCount;
xs?: ColumnType; xs?: ColumnCount;
sm?: ColumnType; sm?: ColumnCount;
md?: ColumnType; md?: ColumnCount;
lg?: ColumnType; lg?: ColumnCount;
xl?: ColumnType; xl?: ColumnCount;
} }
export type ListSize = 'small' | 'default' | 'large'; export type ListSize = 'small' | 'default' | 'large';
@ -48,6 +50,10 @@ export interface ListProps {
locale?: Object; locale?: Object;
} }
export interface ListLocale {
emptyText: string;
}
export default class List extends React.Component<ListProps> { export default class List extends React.Component<ListProps> {
static Item: typeof Item = Item; static Item: typeof Item = Item;
@ -64,7 +70,7 @@ export default class List extends React.Component<ListProps> {
pagination: false, pagination: false,
}; };
private keys = {}; private keys: {[key: string]: string} = {};
getChildContext() { getChildContext() {
return { return {
@ -72,7 +78,7 @@ export default class List extends React.Component<ListProps> {
}; };
} }
renderItem = (item, index) => { renderItem = (item: React.ReactElement<any>, index: number) => {
const { dataSource, renderItem, rowKey } = this.props; const { dataSource, renderItem, rowKey } = this.props;
let key; let key;
@ -98,7 +104,7 @@ export default class List extends React.Component<ListProps> {
return !!(loadMore || pagination || footer); return !!(loadMore || pagination || footer);
} }
renderEmpty = (contextLocale) => { renderEmpty = (contextLocale: ListLocale) => {
const locale = { ...contextLocale, ...this.props.locale }; const locale = { ...contextLocale, ...this.props.locale };
return <div className={`${this.props.prefixCls}-empty-text`}>{locale.emptyText}</div>; return <div className={`${this.props.prefixCls}-empty-text`}>{locale.emptyText}</div>;
} }
@ -155,8 +161,8 @@ export default class List extends React.Component<ListProps> {
let childrenContent; let childrenContent;
if (dataSource.length > 0) { if (dataSource.length > 0) {
const childrenList = React.Children.map(dataSource.map((item: any, index) => this.renderItem(item, index)), const items = dataSource.map((item: any, index: number) => this.renderItem(item, index));
(child: any, index) => React.cloneElement(child, { const childrenList = React.Children.map(items, (child: any, index) => React.cloneElement(child, {
key: this.keys[index], key: this.keys[index],
}), }),
); );