首页 新闻 会员 周边

typescript: 正则表达式匹配时无法使用 matchAll

0
悬赏园豆:30 [已解决问题] 解决于 2023-12-04 12:19

下面的 ts 代码编译时报错 Property 'matchAll' does not exist

const regex = /!\[(\[.+?\])\][\s\S]+?\1:\s*(.*?)\s+/g
const matches = text.matchAll(regex)

请问如何解决这个问题?

dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2023-12-04 11:38
< >
分享
最佳答案
0

是 tsconfig.json 中 "target": "ES2015" 引起的,改为 "target": "ES2020" 即可解决

{
    "compilerOptions": {
      "target": "ES2020",
      "module": "ES2020",
      "strict": true,
      "esModuleInterop": true,
      "forceConsistentCasingInFileNames": true
    }
}
dudu | 高人七级 |园豆:30994 | 2023-12-04 12:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册