When running tsc
on a react-native project, I'm getting a type error in one of the node_modules libraries:
node_modules/react-native-swiper-flatlist/src/components/SwiperFlatList/SwiperFlatList.tsx:79:17 - error TS7031: Binding element '_index' implicitly has an 'any' type.
79 ({ index: _index, prevIndex: _prevIndex }) => {
tsc
shouldn't be checking node_modules, as it's explicetely ignored in the tsconfig.json:
{
"extends": "expo/tsconfig.base",
"include": ["src", "storybook", "types"],
"exclude": ["node_modules", "babel.config.js"],
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"incremental": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["es6"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"strictNullChecks": true,
"target": "esnext",
"module": "esnext",
"baseUrl": ".",
"paths": {
"~*": ["./src/*"]
}
}
}
I saw a related post on ignoring node_modules, and it suggested adding "skipLibCheck": true
to the tsconfig.json, but that didn't change anything.
I'm importing react-native-swiper-flatlist
in one place the following way:
import { SwiperFlatList } from "react-native-swiper-flatlist";
Using typescript v4.7.3.
Any idea why tsc
would be picking up this one specific file, and any suggestions on how to exclude it from being checked?
CodePudding user response:
Looking at the docs for exclude, it doesn't guarantee that the files will be excluded, it just changes the discovery search pattern. If you include the files via import into your main codebase, the files will still be included.
If you want to use that file, you will just need to turn off the implicit any check via the tsconfig flag:
{
"extends": "expo/tsconfig.base",
"include": ["src", "storybook", "types"],
"exclude": ["node_modules", "babel.config.js"],
"compilerOptions": {
//... your other options
"noImplicitAny": false
}
}