首页 新闻 会员 周边

typescript 4 升级到 typescript 5 遇到的 RegExpMatchArray 问题

0
悬赏园豆:30 [已解决问题] 解决于 2024-04-05 21:32

typescript 4.8 升级到 typescript 5.4.3 之后,下面的报错

detect(html: string): RegExpMatchArray {
    return html.match(scriptDetectRegex) ?? [];
}

错误信息如下

 Type 'RegExpMatchArray | []' is not assignable to type 'RegExpMatchArray'.
      Property '0' is missing in type '[]' but required in type 'RegExpMatchArray'.

请问如何解决?

dudu的主页 dudu | 高人七级 | 园豆:30948
提问于:2024-04-05 20:43
< >
分享
最佳答案
0

通过下面的代码解决了

detect(html: string): RegExpMatchArray | [] {
    return html.match(scriptDetectRegex) || [];
}
dudu | 高人七级 |园豆:30948 | 2024-04-05 21:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册