小编You*_*suf的帖子

属性“ matchAll”在“字符串”类型上不存在

我想在字符串上应用Reg表达式。为了获得所有组的结果,我使用matchAll方法。这是我的代码

const regexp = RegExp('foo*','g'); 
const str = "table football, foosball";
let matches = str.matchAll(regexp);

for (const match of matches) {
   console.log(match);
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码编译期间,我得到了错误

类型““桌上足球,桌上足球”上不存在属性'matchAll'

在搜索此错误期间,我在stackoverflow上发现了类似的问题

TS2339:类型“字符串”上不存在属性“包含”

我按上面链接中所述更改了tsconfig配置,但我的问题没有解决

这是我的tsconfig代码;

{
 "compileOnSave": false,
 "compilerOptions": {
 "baseUrl": "./",
 "importHelpers": true,
 "outDir": "./dist/out-tsc",
 "sourceMap": true,
 "declaration": false,
 "module": "es2015",
 "moduleResolution": "node",
 "emitDecoratorMetadata": true,
 "experimentalDecorators": true,
 "target": "es2016",
 "typeRoots": [
  "node_modules/@types"
 ],
"lib": [
  "es2018",
  "dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)

typescript angular7

13
推荐指数
1
解决办法
3912
查看次数

标签 统计

angular7 ×1

typescript ×1