I have found this question asked in many many many places but not a single one of the answers has worked for me. My hunch is that it has something to do with me working in react-native but I am uncertain.
Basically I can't use es7 Array properties like find
or includes
without my linter claiming there is an error. There isn't one (the react-native Javascript environment includes this properties) but no matter what I do I can't remove the error.
The bulk of responses to this issue center around altering tsconfig.json
, specifically the lib
or target
properties.
My current tsconfig.json
is:
{
"compilerOptions": {
"allowJs": true,
"target": "esnext",
"outDir": "dist",
"module": "commonjs",
"sourceMap": true,
"lib": ["es2016.array.include"],
"jsx": "react-native",
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Based on the documentation es2016.array.include
is a valid value for the lib property but I still see the error Property includes does not exist on type any[]
.
I have tried setting target to es2015, es2016, es2017, es2018, es5, es6, and esnext. I have tried adding various things to my lib param including es6, es6, es7, dom, es2016, es2017, es2018, esnext, and the specific properties like es2106.array.includes but none of these values or any combination remove this error from my linter.
tsc
? – Wainagetsconfig.json
change is only supposed to act during transpilation. It doesn't add polyfills for the function, which will not exist on React Native executables (since they tend to use an old version of JavaScriptCore on Android). In that case you'd need to add them through core-js or other polyfills. React Native is supposed to come with those through babel, but I wonder how complete it is. – zehArray.includes
andArray.find
are polyfilled in all react-native javascript runtimes: facebook.github.io/react-native/docs/javascript-environment – Robbie Milejczak