我目前試圖將此代碼移植到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
}