Property 'matchAll' does not exist on type 'string'
Checking the ts signature for the String
and RegExp
classes I realized there is no signature for matchAll
. One manner to solve it could be:
let matches = str['matchAll'](regexp);
Another way would be adding the method to lib.es5.d.ts
file
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"]
}