Categories
TypeScript Answers

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

Spread the love

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

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

How to fix the "Property ‘replaceAll’ does not exist on type ‘string’" error with TypeScript?

To fix the "Property ‘replaceAll’ does not exist on type ‘string’" error with TypeScript, we should add "ES2021.String" into the compilerOptions.lib array.

To do this, we write

{
  //..,
  "compilerOptions": {
    //...,
    "lib": [
      //...,
      "ES2021.String"
    ]
  }
}

to add "ES2021.String" into compilerOptions.lib in tsconfig.json.

Then the TypeScript compiler will know that the string replaceAll method is available for use in our TypeScript project.

Conclusion

To fix the "Property ‘replaceAll’ does not exist on type ‘string’" error with TypeScript, we should add "ES2021.String" into the compilerOptions.lib array.

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 *