[ts]Property ‘screenWidth‘ does not exist on type ‘Window & typeof globalThis‘.ts(2339)
problem
window.onresize = () => { return (() => { // ts报错:Property 'screenWidth' does not exist on type 'Window & typeof globalThis'.ts(2339) window.screenWidth = document.body.clientWidth; state.screenWidth = window.screenWidth; })(); };
复制
reason
ts不认识window下的screenWidth
solution
声明类型,根目录下的类型声明
// global.d.ts declare global { interface Window { screenWidth:any; } } export {};
复制