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

后端 未结 3 548
忘掉有多难
忘掉有多难 2020-12-01 13:50

Getting the error

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

in node_modules/ng2-breadcrumb/app/components/bread

相关标签:
3条回答
  • 2020-12-01 13:55

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

    0 讨论(0)
  • 2020-12-01 13:59

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

    0 讨论(0)
  • 2020-12-01 14:14

    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).

    0 讨论(0)
提交回复
热议问题