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