我目前试图将此代码移植到TypeScript中。将JavaScript requestAnimFrame移植到TypeScript
if (typeof window !== 'undefined') {
window.requestAnimFrame = (function(callback){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000/60, new Date().getTime());
};
})();
}
TSC中的错误,我得到的是:
提供的参数不匹配,通话对象的任何签名
我已经试过声明的interface WindowEx extends Window
包含签名,然后铸造(< WindowEx>window).xxx
,但我怀疑这是转换这个“典型”代码的正确方法。
尝试:
interface WindowEx extends Window {
requestAnimFrame(callback, target?):number;
webkitRequestAnimationFrame(callback, target?):number;
mozRequestAnimationFrame(callback, target?):number;
oRequestAnimationFrame(callback, target?):number;
// msRequestAnimationFrame already at WindowAnimationTiming interface
}