New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES7 Array.prototype.includes() missing in TypeScript #2340
Comments
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. |
Suggest fixing the typo in the title for searching purposes |
@rolyp fixed. |
ES6 is not widely or fully supported yet. Adding ES7 functionality to lib.d.ts seems premature unless this is actually usable in many places. If we put this in lib.d.ts right now then a bunch of people will dot off of arrays and see a handy So then our options are to try to polyfill all the functionality of a moving spec (since if we do this for |
I guess 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 |
There's a big difference between language features and polyfills, though. If you have polyfilled If you haven't, then it's almost certainly not going to work in a majority of runtimes, and it'd be a mistake to put in in lib.d.ts until that's not the case. |
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 |
Awesome. Is ES7 lib.d.ts due to ship with TS 2.0? |
Hi, I am using typescript next and cannot get Array.prototype.includes to work. I get the following errors: Property 'includes' does not exist on type 'string[]' For what it's worth I also am seeing errors around lib.es2016.d.ts and lib.es2017.d.ts not being in the compilation context which is probably why things are not working. Here is my tsconfig if that heps:
|
Nevermind, I fixed this by adding lib:["es2016", "dom"] to the compiler options in tsconfig.json |
I had to add |
With |
@sinedied I think this was released in final 2.1, so you will probably need +2.1 for this to work. |
Can confirm that |
I still see this issue with TS 2.3.2 and |
please file a new issue and share a self-contained repro |
Make sure you put |
Working for me with TS ^2.3.2 in package.json and |
I also have the same problems as @samrae7 with the following configuration:
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 |
Typescript does not includes any polyfills, you have to include them yourself. |
@jgerstle @pendar747 This comment gets TS working with |
I'm still having issues with this: http://kangax.github.io/compat-table/es2016plus/ using tsc 2.7.2 |
@NullVoxPopuli please see #2340 (comment) |
For what it's worth, I had to restart VSCode to force it to reload |
@0vidiu in deed, VSCode take its time to reload the |
@michaeljota Maybe I was just impatient :) |
It worked for me. "lib": [
"dom",
"es2017"
], My typescript version is 2.4.2, now |
|
thanks @fvsch , remember to restart VSCode |
Yup... restarting vscode was necessary. |
#2340 (comment) or just select |
Seems like the ES7
.includes()
method is missing in TypeScript.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
The text was updated successfully, but these errors were encountered: