Categories
TypeScript Answers

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

Spread the love

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

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

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

To fix the "Property ‘includes’ does not exist on type ‘string[]’" error with TypeScript, we can add the 'es2017' option to the compilerOptions.lib option in tsconfig.json.

For instance, we write

{
  //...
  "compilerOptions": {
    //...
    "lib": ["es6", "dom", "es2017"],
    //...
    "target": "es5"
    //...
  }
  //...
}

to add "es2017" into the lib array so that the TypeScript compiler knows that ES2017 features are available for use in our TypeScript project.

Conclusion

To fix the "Property ‘includes’ does not exist on type ‘string[]’" error with TypeScript, we can add the 'es2017' option to the compilerOptions.lib option 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 *