From 541b9d146ab11d7ffd650ca122130dd5cdb1b109 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Wed, 22 Nov 2017 12:06:49 +0800 Subject: [PATCH] Fix implicit any error for _util --- components/_util/callMoment.tsx | 3 +-- components/_util/getRequestAnimationFrame.tsx | 12 ++++++----- components/_util/isCssAnimationSupported.tsx | 4 ++-- components/_util/openAnimation.tsx | 20 +++++++++---------- components/_util/throttleByAnimationFrame.tsx | 12 +++++------ components/_util/triggerEvent.tsx | 2 +- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/components/_util/callMoment.tsx b/components/_util/callMoment.tsx index 58933fe9d4..4f46c3d4c9 100644 --- a/components/_util/callMoment.tsx +++ b/components/_util/callMoment.tsx @@ -1,5 +1,4 @@ // https://github.com/moment/moment/issues/3650 - -export default function callMoment(moment, ...args) { +export default function callMoment(moment: any, ...args: any[]) { return (moment.default || moment)(...args); } diff --git a/components/_util/getRequestAnimationFrame.tsx b/components/_util/getRequestAnimationFrame.tsx index 5d3cecf676..597426fb70 100644 --- a/components/_util/getRequestAnimationFrame.tsx +++ b/components/_util/getRequestAnimationFrame.tsx @@ -2,7 +2,7 @@ const availablePrefixs = ['moz', 'ms', 'webkit']; function requestAnimationFramePolyfill() { let lastTime = 0; - return function(callback) { + return function(callback: (n: number) => void) { const currTime = new Date().getTime(); const timeToCall = Math.max(0, 16 - (currTime - lastTime)); const id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); @@ -23,11 +23,11 @@ export default function getRequestAnimationFrame() { const prefix = availablePrefixs.filter(key => `${key}RequestAnimationFrame` in window)[0]; return prefix - ? window[`${prefix}RequestAnimationFrame`] + ? (window as any)[`${prefix}RequestAnimationFrame`] : requestAnimationFramePolyfill(); } -export function cancelRequestAnimationFrame(id) { +export function cancelRequestAnimationFrame(id: number) { if (typeof window === 'undefined') { return null; } @@ -39,6 +39,8 @@ export function cancelRequestAnimationFrame(id) { )[0]; return prefix ? - (window[`${prefix}CancelAnimationFrame`] || window[`${prefix}CancelRequestAnimationFrame`]).call(this, id) - : clearTimeout(id); + ( + (window as any)[`${prefix}CancelAnimationFrame`] || + (window as any)[`${prefix}CancelRequestAnimationFrame`] + ).call(this, id) : clearTimeout(id); } diff --git a/components/_util/isCssAnimationSupported.tsx b/components/_util/isCssAnimationSupported.tsx index 45d51bb356..e6fd21d408 100644 --- a/components/_util/isCssAnimationSupported.tsx +++ b/components/_util/isCssAnimationSupported.tsx @@ -1,4 +1,4 @@ -let animation; +let animation: boolean; function isCssAnimationSupported() { if (animation !== undefined) { @@ -11,7 +11,7 @@ function isCssAnimationSupported() { } if (animation !== undefined) { for (let i = 0; i < domPrefixes.length; i++) { - if (elm.style[`${domPrefixes[i]}AnimationName`] !== undefined) { + if ((elm.style as any)[`${domPrefixes[i]}AnimationName`] !== undefined) { animation = true; break; } diff --git a/components/_util/openAnimation.tsx b/components/_util/openAnimation.tsx index 4ce25c3dc0..ac1d6e5fdc 100644 --- a/components/_util/openAnimation.tsx +++ b/components/_util/openAnimation.tsx @@ -3,18 +3,18 @@ import getRequestAnimationFrame, { cancelRequestAnimationFrame } from './getRequ const reqAnimFrame = getRequestAnimationFrame(); -function animate(node, show, done) { - let height; - let requestAnimationFrameId; +function animate(node: HTMLElement, show: boolean, done: () => void) { + let height: number; + let requestAnimationFrameId: number; return cssAnimation(node, 'ant-motion-collapse', { start() { if (!show) { node.style.height = `${node.offsetHeight}px`; - node.style.opacity = 1; + node.style.opacity = '1'; } else { height = node.offsetHeight; - node.style.height = 0; - node.style.opacity = 0; + node.style.height = '0 px'; + node.style.opacity = '0'; } }, active() { @@ -23,7 +23,7 @@ function animate(node, show, done) { } requestAnimationFrameId = reqAnimFrame(() => { node.style.height = `${show ? height : 0}px`; - node.style.opacity = show ? 1 : 0; + node.style.opacity = show ? '1' : '0'; }); }, end() { @@ -38,13 +38,13 @@ function animate(node, show, done) { } const animation = { - enter(node, done) { + enter(node: HTMLElement, done: () => void) { return animate(node, true, done); }, - leave(node, done) { + leave(node: HTMLElement, done: () => void) { return animate(node, false, done); }, - appear(node, done) { + appear(node: HTMLElement, done: () => void) { return animate(node, true, done); }, }; diff --git a/components/_util/throttleByAnimationFrame.tsx b/components/_util/throttleByAnimationFrame.tsx index 657fcbfea5..213b213d5d 100644 --- a/components/_util/throttleByAnimationFrame.tsx +++ b/components/_util/throttleByAnimationFrame.tsx @@ -2,27 +2,27 @@ import getRequestAnimationFrame, { cancelRequestAnimationFrame } from '../_util/ const reqAnimFrame = getRequestAnimationFrame(); -export default function throttleByAnimationFrame(fn) { - let requestId; +export default function throttleByAnimationFrame(fn: () => void) { + let requestId: number | null; - const later = args => () => { + const later = (args: any[]) => () => { requestId = null; fn(...args); }; - const throttled = (...args) => { + const throttled = (...args: any[]) => { if (requestId == null) { requestId = reqAnimFrame(later(args)); } }; - (throttled as any).cancel = () => cancelRequestAnimationFrame(requestId); + (throttled as any).cancel = () => cancelRequestAnimationFrame(requestId!); return throttled; } export function throttleByAnimationFrameDecorator() { - return function(target, key, descriptor) { + return function(target: any, key: string, descriptor: any) { let fn = descriptor.value; let definingProperty = false; return { diff --git a/components/_util/triggerEvent.tsx b/components/_util/triggerEvent.tsx index 40b37473d0..3c8cfc5414 100644 --- a/components/_util/triggerEvent.tsx +++ b/components/_util/triggerEvent.tsx @@ -1,4 +1,4 @@ -export default function triggerEvent(el, type) { +export default function triggerEvent(el: Element, type: string) { if ('createEvent' in document) { // modern browsers, IE9+ const e = document.createEvent('HTMLEvents');