0
votes

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.

1
So the code executes but the linter complains? Which version of tsc?Wainage
Where do you see the error, during transpilation or during execution? The tsconfig.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.zeh
okay I am new to typescript so I did not realize that. This error is only being shown via tslint in VSCode. When I compile it isn't present, so I guess I'm barking up the wrong tree?Robbie Milejczak
also fwiw Array.includes and Array.find are polyfilled in all react-native javascript runtimes: facebook.github.io/react-native/docs/javascript-environmentRobbie Milejczak

1 Answers

0
votes

it helps me

In tsconfig.json "lib": ["es6", "ES2016.Array.Include"],