TypeScript: ES7 Array.prototype.includes() missing in TypeScript

Seems like the ES7 .includes() method is missing in TypeScript.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 58
  • Comments: 36 (10 by maintainers)

Most upvoted comments

Can confirm that Version 2.1.5 with "lib":["dom","es2017"] includes includes

Nevermind, I fixed this by adding lib:[“es2016”, “dom”] to the compiler options in tsconfig.json

Where is there an implementation of this that can be used? It doesn’t make much sense for us to add things to lib.d.ts that aren’t readily available. You can always augment the definition of Array yourself if your environment does support this.

@danquirk It has a wide implementation area, that’s why it will be included in ES7.

I’m not sure what TypeScript’s goal is? to include everything in ES6/ES7? I think people expect TypeScript to be a superset of Javascript, because that’s what you have mentioned? Thus, implying that you compile everything and beyond BabelJS. And BabelJS compile ES6 and ES7 down to ES5 and ES3.

It would be good if TypeScript had one feature table also like BabelJS’s http://babeljs.io/docs/compare/. It makes it easier for developer to understand which feature is available.

What you need is “es2016.array.include” in your “lib” config.

How about now? It appears the majority of runtimes support it now: Chrome 47, Firefox 43, Opera 34, Safari 9, Android Webview, Firefox Mobile 43, Opera Mobile 34, Safari Mobile 9, Chrome for Android 47. Missing support: Internet Explorer, Edge, Android, IE Mobile.

For now, I’ll augment my Array definition locally. Just thought perhaps it was time you guys revisit it.

ES7 features will be in the ES7 lib.d.ts target

I still see this issue with TS 2.3.2 and “lib”:[“dom”, “es2017”]

Make sure you put lib into compilerOptions.

I had to add "es2016.array.include" instead. Don’t know if it is any different, but for information sake.

I still see this issue with TS 2.3.2 and "lib":["dom", "es2017"]

I guess ES6 and ES7 are not widely used yet. So isn’t TypeScript. It seems like the large JS community is embracing ES6/ES7 to ES5 transpilers, especially BabelJS. The reason I choose to code in TS instead of ES6 is because TypeScript supports types and other nice features. But I’ve learnt the hard way — that some features are only available if the compile target is ES6, this is NOT good. Because of legacy issues and ES6 is not widely adopted — I think everything should be able to compile down to ES5.

I guess many people are using the new ES7 features in BabelJS. Why wouldn’t they? And if you look at their downloads they are almost in par with or higher than TypeScript, in a very short time: http://npm-stat.com/charts.html?package=babel

https://github.com/Microsoft/TypeScript/issues/2340#issuecomment-382621228 or just select restart TS server in VSCode command menu

"lib": ["es2017", "dom"] and a VSCode restart needed for me too.

For what it’s worth, I had to restart VSCode to force it to reload tsconfig.json after updating the lib array. That stopped it from bugging be.

@jgerstle @pendar747 This comment gets TS working with Array.includes on v2.6.2

With typescript@2.0.10 and ["es6", "es2016", "dom"] it does not work for me (and neither with "es2016.array.include")?

Yup… restarting vscode was necessary.

It worked for me. I’ve change the lib property to (tsconfig.json)

"lib": [
      "dom",
      "es2017"
    ],

My typescript version is 2.4.2, now Array.prototype.include is included

I still see this issue with TS 2.3.2 and “lib”:[“dom”, “es2017”]

please file a new issue and share a self-contained repro