【发布时间】:2021-08-08 09:00:34
【问题描述】:
我想知道,这段代码如何给出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) 中
【问题讨论】:
标签: typescript undefined null-check