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
I also have the same problems as @samrae7 with the following configuration:
{
"compilerOptions": {
"module": "commonjs",
"removeComments": true,
"lib": [
"dom",
"es2017"
],
"sourceMap": true,
"outDir": "../dist",
"target": "es6",
"watch": true,
"allowJs": true,
"typeRoots": [ "node_modules/@types" ]
},
"exclude": [
"node_modules"
],
"compileOnSave": true
}
P.S. Using version 2.4.2 of typescript
Includes is part of es2016, and you don't seem to have it in lib. 😄. Just add it there, it should work.
What you need is "es2016.array.include" in your "lib" config.
I was able to get typescript to compile the array.includes by changing my lib from "lib": ["dom", "es2015"] to "lib": ["dom", "es2016"]. However I get the following in ie11: ERROR TypeError: Object doesn't support property or method 'includes'. Do I need to add a polyfill in addition? I thought typescript handles that my target is es5.
Typescript does not includes any polyfills, you have to include them yourself.
@jgerstle @pendar747 This comment gets TS working with Array.includes on v2.6.2
I'm still having issues with this:
http://kangax.github.io/compat-table/es2016plus/
using tsc 2.7.2
@NullVoxPopuli please see https://github.com/Microsoft/TypeScript/issues/2340#issuecomment-316664621
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.
@0vidiu in deed, VSCode take its time to reload the tsconfig changes, but it shouldn't need a restart.
@michaeljota Maybe I was just impatient :)
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
"lib": ["es2017", "dom"] and a VSCode restart needed for me too.
thanks @fvsch , remember to restart VSCode
Yup... restarting vscode was necessary.
https://github.com/Microsoft/TypeScript/issues/2340#issuecomment-382621228 or just select restart TS server in VSCode command menu