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

Created on 27 Oct 2016  路  8Comments  路  Source: microsoft/TypeScript

Hi,

I am trying to use
Array.prototype.includes includes function explained on MDN network but I am getting the following error:

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

includes is part of EcmaScript 6.

I am using Typescript version 2.0.3

Question

Most helpful comment

change 'target' worked for me:

{ "compilerOptions": { "target": "es2016", }, }

All 8 comments

use --lib es2015 (since it is ES2015-specific). if you also want the DOM definitions use --lib dom,es2015

Updated
use --lib es2016 (since it is ES2016-specific). if you also want the DOM definitions use --lib dom,es2016

I don't see how this is es2015 specific. Looking at the docs it's included in the es2016 and es2017 specs so adding es2015 doesn't work, at least for me.

So adding any of es2016, es2016.array.include or es2017 works.

thanks @krokofant for the correction. You are right, it is -lib es2016 or --lib dom es2016.

updated comment above

What is the tsconfig.json option for this?

"lib"

You needed to set tsconfig.json compilerOptions.lib from "es6" to "es7" as follows:

"lib": [
  "dom",
  "es7"
],

I'm not sure if this causes other problems, though. "includes" is implemented for 'string' (not Array) in ES6, and for arrays only in ES7.

change 'target' worked for me:

{ "compilerOptions": { "target": "es2016", }, }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dlaberge picture dlaberge  路  3Comments

weswigham picture weswigham  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

wmaurer picture wmaurer  路  3Comments

remojansen picture remojansen  路  3Comments