Property 'abc' does not exist on type 'Window & typeof globalThis'.


Property 'requestIdleCallback' does not exist on type 'Window & typeof globalThis'.

代碼使用了 window 的非標准屬性 requestIdleCallback, ts 飄紅報錯: window 對象上不存在該屬性;

需要手動給 window 聲明該屬性:
在項目 根目錄 或者 src 下的 xx.d.ts 文件中加入:

interface Window {
  requestIdleCallback?: Function;
}

如果項目中沒有 xxx.d.ts 文件就新建一個,但是要注意:tsconfig.json 里的 include 記得包含這個文件;
比如我的 typings.d.ts 在項目根目錄下


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM