Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'matchAll' does not exist on type 'string'

I want to apply Reg Expression on string. In order to get all groups result i am using matchAll method. Here is my code

const regexp = RegExp('foo*','g');  const str = "table football, foosball"; let matches = str.matchAll(regexp);  for (const match of matches) {    console.log(match); } 

during compiling on above code i got error

Property 'matchAll' does not exist on type '"table football, foosball"'

during searching about this error i found similar issue on stackoverflow

TS2339: Property 'includes' does not exist on type 'string'

I changed tsconfig configuration as mention in above link but my issue did not solved

Here is my tsconfig code;

{  "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" ] } } 
like image 917
Yousuf Avatar asked Apr 03 '19 16:04

Yousuf


Video Answer


1 Answers

String.prototype.matchAll() is part of the ECMAScript 2020 specification (draft). In TypeScript you can include these library features by adding es2020 or es2020.string, in the compiler options:

"compilerOptions": {     "lib": ["es2020.string"] } 
like image 154
mvr Avatar answered Oct 13 '22 15:10

mvr