refactor: support noImplicitAny in Alert (#5836)

* refactor(alert): Enable noImplicitAny

* refactor(anchor): enable noImplicitAny #5627

* chore: coding style
This commit is contained in:
2017-04-26 09:51:35 +08:00 committed by Benjy Cui
parent 6cd05d8be5
commit e7053c1b39
4 changed files with 49 additions and 46 deletions

View File

@ -4,7 +4,7 @@ import Animate from 'rc-animate';
import Icon from '../icon';
import classNames from 'classnames';
function noop() {}
function noop() { }
export interface AlertProps {
/**
@ -20,7 +20,7 @@ export interface AlertProps {
/** Additional content of Alert */
description?: React.ReactNode;
/** Callback when close Alert */
onClose?: React.MouseEventHandler<any>;
onClose?: React.MouseEventHandler<HTMLAnchorElement>;
/** Whether to show icon */
showIcon?: boolean;
style?: React.CSSProperties;
@ -30,14 +30,14 @@ export interface AlertProps {
}
export default class Alert extends React.Component<AlertProps, any> {
constructor(props) {
constructor(props: AlertProps) {
super(props);
this.state = {
closing: true,
closed: false,
};
}
handleClose = (e) => {
handleClose = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
let dom = ReactDOM.findDOMNode(this) as HTMLElement;
dom.style.height = `${dom.offsetHeight}px`;

View File

@ -31,7 +31,7 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
anchorHelper: AnchorHelper;
};
private _component: Element;
private _component: HTMLAnchorElement;
setActiveAnchor() {
const { bounds, offsetTop, href, affix } = this.props;
@ -50,25 +50,28 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
this.setActiveAnchor();
}
renderAnchorLink = (child) => {
const { href } = child.props;
if (href) {
this.context.anchorHelper.addLink(href);
return React.cloneElement(child, {
onClick: this.props.onClick,
prefixCls: this.props.prefixCls,
affix: this.props.affix,
offsetTop: this.props.offsetTop,
});
renderAnchorLink = (child: React.ReactChild) => {
// Here child is a ReactChild type
if (typeof child !== 'string' && typeof child !== 'number') {
const { href } = child.props;
if (href) {
this.context.anchorHelper.addLink(href);
return React.cloneElement(child, {
onClick: this.props.onClick,
prefixCls: this.props.prefixCls,
affix: this.props.affix,
offsetTop: this.props.offsetTop,
});
}
}
return child;
}
refsTo = (component) => {
refsTo = (component: HTMLAnchorElement) => {
this._component = component;
}
scrollTo = (e) => {
scrollTo = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
const { onClick, href } = this.props;
const { anchorHelper } = this.context;

View File

@ -3,7 +3,7 @@ import getRequestAnimationFrame from '../_util/getRequestAnimationFrame';
export const reqAnimFrame = getRequestAnimationFrame();
export const easeInOutCubic = (t, b, c, d) => {
export const easeInOutCubic = (t: number, b: number, c: number, d: number) => {
const cc = c - b;
t /= d / 2;
if (t < 1) {
@ -17,7 +17,7 @@ export function getDefaultTarget() {
window : null;
}
export function getOffsetTop(element): number {
export function getOffsetTop(element: HTMLElement): number {
if (!element) {
return 0;
}
@ -28,10 +28,10 @@ export function getOffsetTop(element): number {
const rect = element.getBoundingClientRect();
if ( rect.width || rect.height ) {
if (rect.width || rect.height) {
const doc = element.ownerDocument;
const docElem = doc.documentElement;
return rect.top - docElem.clientTop;
return rect.top - docElem.clientTop;
}
return rect.top;
@ -43,7 +43,7 @@ export type Section = {
section: any;
};
export function scrollTo(href, offsetTop = 0, target = getDefaultTarget, callback = () => {}) {
export function scrollTo(href: string, offsetTop = 0, target = getDefaultTarget, callback = () => { }) {
const scrollTop = getScroll(target(), true);
const targetElement = document.getElementById(href.substring(1));
if (!targetElement) {
@ -68,7 +68,7 @@ export function scrollTo(href, offsetTop = 0, target = getDefaultTarget, callbac
class AnchorHelper {
private links: Array<string>;
private currentAnchor: HTMLElement | null;
private currentAnchor: HTMLAnchorElement | null;
private _activeAnchor: string;
constructor() {
@ -77,17 +77,17 @@ class AnchorHelper {
this._activeAnchor = '';
}
addLink(link) {
addLink(link: string) {
if (this.links.indexOf(link) === -1) {
this.links.push(link);
}
}
getCurrentActiveAnchor(): HTMLElement | null {
getCurrentActiveAnchor(): HTMLAnchorElement | null {
return this.currentAnchor;
}
setActiveAnchor(component) {
setActiveAnchor(component: HTMLAnchorElement) {
this.currentAnchor = component;
}
@ -98,21 +98,21 @@ class AnchorHelper {
}
const linksPositions = (this.links
.map(section => {
const target = document.getElementById(section.substring(1));
if (target && getOffsetTop(target) < offsetTop + bounds) {
const top = getOffsetTop(target);
if (top <= offsetTop + bounds) {
return {
section,
top,
bottom: top + target.clientHeight,
};
.map(section => {
const target = document.getElementById(section.substring(1));
if (target && getOffsetTop(target) < offsetTop + bounds) {
const top = getOffsetTop(target);
if (top <= offsetTop + bounds) {
return {
section,
top,
bottom: top + target.clientHeight,
};
}
}
}
return null;
})
.filter(section => section !== null) as Array<Section>);
return null;
})
.filter(section => section !== null) as Array<Section>);
if (linksPositions.length) {
const maxSection = linksPositions.reduce((prev, curr) => curr.top > prev.top ? curr : prev);
@ -121,7 +121,7 @@ class AnchorHelper {
return '';
}
scrollTo(href, offsetTop, target = getDefaultTarget, callback = () => {}) {
scrollTo(href: string, offsetTop: number | undefined, target = getDefaultTarget, callback = () => { }) {
scrollTo(href, offsetTop, target, callback);
}
}

View File

@ -39,7 +39,7 @@ export default class Anchor extends React.Component<AnchorProps, any> {
private anchorHelper: AnchorHelper;
private _avoidInk: boolean;
constructor(props) {
constructor(props: AnchorProps) {
super(props);
this.state = {
activeAnchor: null,
@ -85,7 +85,7 @@ export default class Anchor extends React.Component<AnchorProps, any> {
}
}
clickAnchorLink = (href, component) => {
clickAnchorLink = (href: string, component: HTMLElement) => {
this._avoidInk = true;
this.refs.ink.style.top = `${component.offsetTop + component.clientHeight / 2 - 4.5}px`;
this.anchorHelper.scrollTo(href, this.props.offsetTop, getDefaultTarget, () => {
@ -93,10 +93,10 @@ export default class Anchor extends React.Component<AnchorProps, any> {
});
}
renderAnchorLink = (child) => {
renderAnchorLink = (child: React.ReactElement<any>) => {
const { href } = child.props;
if (child.type.__ANT_ANCHOR_LINK && href) {
const { type } = child as any;
if (type.__ANT_ANCHOR_LINK && href) {
this.anchorHelper.addLink(href);
return React.cloneElement(child, {
onClick: this.clickAnchorLink,