Categories
TypeScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *