From this question and the accepted answer, I know that there is an methode to check if an array includes an object in JavaScript by using this line of code:
> ['joe', 'jane', 'mary'].includes('jane'); true
However if I use the same code in TypeScript I've got this error:
Property
includesdoes not exist on typestring[].
Includes is defined in the lib.es2016.array.include.d.ts since it is part of the es2016 standard. You can include this lib in your tsconfig but you have to provide your own polyfil for the method:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"scripthost",
"es5",
"es2016.array.include"
]
}
}
You can also provide the polyfill by assigning Array.prototype.include if your runtime does not provide this method on array (you can get a polyfill from here for example)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With