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,7 +50,9 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
this.setActiveAnchor();
}
renderAnchorLink = (child) => {
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);
@ -61,14 +63,15 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
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,7 +28,7 @@ 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;
@ -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;
}
@ -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,