sgo*_*lez 5 typescript react-native react-typescript
在react-native项目上运行时tsc,我在node_modules库之一中遇到类型错误:
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 }) => {
Run Code Online (Sandbox Code Playgroud)
tsc不应该检查 node_modules,因为它在 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/*"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我看到一篇关于忽略 node_modules 的相关文章,它建议添加 "skipLibCheck": true到 tsconfig.json,但这并没有改变任何东西。
我react-native-swiper-flatlist通过以下方式导入一处:
import { SwiperFlatList } from "react-native-swiper-flatlist";
Run Code Online (Sandbox Code Playgroud)
使用打字稿 v4.7.3。
知道为什么tsc会选择这个特定文件,以及有关如何将其排除在检查之外的任何建议吗?
小智 3
查看排除文档,它并不能保证文件将被排除,它只是更改发现搜索模式。如果您通过导入将文件包含到主代码库中,则这些文件仍将包含在内。
如果您想使用该文件,您只需通过 tsconfig 标志关闭隐式任何检查:
{
"extends": "expo/tsconfig.base",
"include": ["src", "storybook", "types"],
"exclude": ["node_modules", "babel.config.js"],
"compilerOptions": {
//... your other options
"noImplicitAny": false
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2616 次 |
| 最近记录: |