【发布时间】:2018-05-14 09:02:24
【问题描述】:
我收到以下错误
error TS7016: Could not find a declaration file for module 'react-native-camera'. '/Users/ilja/Documents/Repositories/blok/node_modules/react-native-camera/index.js' implicitly has an 'any' type.
Try `npm install @types/react-native-camera` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-camera';`
作为快速修复,我在项目的根目录下创建了typings/index.d.ts(没有@types/react-native-camera)文件并用
declare module 'react-native-camera';
然后,在我的 tsconfig 文件中,我像这样将它添加到我的类型根中
"typeRoots": ["node_modules/@types", "./typings"],
但是我在构建时仍然遇到同样的错误,导致我认为我的实现不正确,我错过了什么?
编辑,我的完整 tsconfig 看起来像这样
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"lib": ["es7"],
"allowJs": true,
"checkJs": true,
"jsx": "react-native",
"removeComments": true,
"outDir": "./dist",
"typeRoots": ["node_modules/@types", "./typings"],
"experimentalDecorators": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"strict": true
},
"exclude": ["./node_modules", "./android", "./ios", "./assets", "./__tests__", "./dist"],
"include": ["./src"]
}
【问题讨论】:
标签: reactjs typescript react-native node-modules typescript-typings