如何在流中检查对象属性是否有条件?

时间:2017-05-10 23:01:56

标签: flowtype

我有一些基本上看起来像的代码:

blur()

哪个Flow会抛出错误if ('serviceWorker' in navigator) { navigator.serviceWorker.register('something') } 。由于我已经对Method cannot be called on possibly undefined value现有的检查进行了检查,我如何才能确认Flow是否可以保证?

1 个答案:

答案 0 :(得分:3)

试试这个:

if ( typeof navigator.serviceWorker !== 'undefined' )

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/typeof