2016-09-29 92 views
1

没有找到可转位签名我使用这个片段获取视野访问计算属性/元素。在HTML元素

function getViewport(): { width: number, height: number } { 
    let e = window; 
    let a = 'inner'; 

    if (!('innerWidth' in window)) { 
    a = 'client'; 
    e = document.documentElement || document.body; 
    } 

    return { 
    width: e[`${a}Width`], 
    height: e[`${a}Height`], 
    }; 
} 

的大小,但是当我运行flow check我收到此错误:

18:  height: e[`${a}Height`], 
       ^^^^^^^^^^^^^^^ access of computed property/element. Indexable signature not found in 
18:  height: e[`${a}Height`], 
       ^HTMLElement 

我刚开始学习流动,如果有人会向我解释我该如何解决这个问题,或者当我可以阅读更多关于它的文档时,我会非常感谢。谢谢。

回答

2

取决于你想要做什么,但更容易的解决方法是:

let e: Object = window;