打字稿,对象可能在空检查中未定义

问题描述

我想知道,这段代码如何给出 object is possibly undefined error

  if (newFocus) {
    if (viewCache[viewId] !== undefined) {
      dispatch(ViewActions.focusOn(viewCache[viewId].focus));
    } else {
      dispatch(ViewActions.focusOn(newFocus));
    }
  }

第 3 行给我错误viewCache[viewId] is possibly undefined 即使包裹在 if (viewCache[viewId] !== undefined)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)