How to fix the “Property ‘matchAll’ does not exist on type ‘string’” error with TypeScript?

Sometimes, we want to fix the “Property ‘matchAll’ does not exist on type ‘string’” error with TypeScript.

In this article, we’ll look at how to fix the “Property ‘matchAll’ does not exist on type ‘string’” error with TypeScript.

How to fix the “Property ‘matchAll’ does not exist on type ‘string’” error with TypeScript?

To fix the “Property ‘matchAll’ does not exist on type ‘string’” error with TypeScript, we can add the "es2020.string" entry into compilerOptions.lib in tsconfig.json.

For instance, we write

{
  //...
  "compilerOptions": {
    "lib": ["es2020.string"]
  }
  //...
}

to add the "es2020.string" entry into compilerOptions.lib in tsconfig.json.

Then the TypeScript compiler knows that the string matchAll method is available for use in our TypeScript project.

Conclusion

To fix the “Property ‘matchAll’ does not exist on type ‘string’” error with TypeScript, we can add the "es2020.string" entry into compilerOptions.lib in tsconfig.json.