Property 'includes' does not exist on type 'string[]'

北城以北 提交于 2019-11-28 10:41:28

Add "ES2017" to your "lib" array in tsconfig.json:

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

This should work since TypeScript 2.1.

A related issue.

Explanation

The includes method on Array is supported since ES7 (ES2016). The above will add a missing library file to compilation.

The TypeScript compiler options are documented here.

Lib es2016 or es7 may be sufficient instead of es2017 (not tested).

Black Glory

Changing the compiler target to "es2016" in tsconfig.js should solve this issue.

If you don't want to change to es2016, just use arr.indexOf(valueToCheck) !== -1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!