Fix implicit any error for _util

This commit is contained in:
Wei Zhu 2017-11-22 12:06:49 +08:00
parent b8a08f6e1d
commit 541b9d146a
6 changed files with 27 additions and 26 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
},
};

View File

@ -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 {

View File

@ -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');