代码:
var iframeEl = document.getElementById('cases-iframe') as HTMLIFrameElement;
if (iframeEl) {
iframeEl.contentWindow.postMessage(msg, '*');
}
错误:
[ts] Object is possibly 'null'.
(local var) iframeEl: HTMLIFrameElement
当我有一个防止null的if语句时,为什么会出现此错误?以及如何解决这个错误?