HarmonyOS Object is possibly 'undefined'. <ArkTSCheck>报错

已经判断了变量是否为空,仍然会报错

HarmonyOS
2024-12-18 16:48:20
1184浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

参照以下写法

if (this.port_pair_map != undefined && this.port_pair_map.get("123") != undefined) {
  let arr: webview.WebMessagePort[] = this.port_pair_map.get("123") as webview.WebMessagePort[]
    // arr[1].postMessageEvent("11111")
  (this.port_pair_map.get("123") as webview.WebMessagePort[])[1].postMessageEvent("1111")
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
分享
微博
QQ
微信
回复
2024-12-18 19:07:55
相关问题
使用fetch报错,fetch undefined
8247浏览 • 2回复 待解决
HarmonyOS Object.assign(target, source)报错
2208浏览 • 2回复 待解决
HarmonyOS Objectobject的区别
1298浏览 • 1回复 待解决
HarmonyOS [object, object]是如何读取的?
868浏览 • 1回复 待解决
ArkTSCheck检查不允许使用any
1777浏览 • 1回复 待解决
HarmonyOS Object接口解析
676浏览 • 1回复 待解决
HarmonyOS Map转Object
719浏览 • 1回复 待解决
HarmonyOS List提示undefined
448浏览 • 1回复 待解决