我有一些基本上看起来像的代码:
blur()
哪个Flow会抛出错误if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('something')
}
。由于我已经对Method cannot be called on possibly undefined value
现有的检查进行了检查,我如何才能确认Flow是否可以保证?
答案 0 :(得分:3)
试试这个:
if ( typeof navigator.serviceWorker !== 'undefined' )
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/typeof