我剛剛開始使用Typescript,我試圖將它與新的React Native項目一起使用。但是,我可以讓TS編譯。除了使用npm @types之外,我的安裝基於this article。我得到正確的類型提示在我的IDE(原子),但是當我嘗試編譯,我得到以下錯誤:Typescript 2.0 with React Native
node_modules/@types/react-native/index.d.ts(19,24): error TS2307: Cannot find module 'react'.
node_modules/@types/react-native/index.d.ts(222,28): error TS2304: Cannot find name 'Component'.
node_modules/@types/react-native/index.d.ts(1017,15): error TS2304: Cannot find name 'Ref'.
...
我的package.json
{
"name": "healthymeIngage",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "15.3.2",
"react-native": "0.35.0"
},
"jest": {
"preset": "jest-react-native"
},
"devDependencies": {
"@types/react": "^0.14.41",
"@types/react-native": "^0.29.36",
"babel-jest": "16.0.0",
"babel-preset-react-native": "1.9.0",
"jest": "16.0.2",
"jest-react-native": "16.0.0",
"react-test-renderer": "15.3.2",
"typescript": "^2.0.3"
}
}
我tsconfig.json
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"jsx": "react",
"outDir": "build",
"rootDir": "src",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"sourceMap": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"node_modules/@types/**/*.ts"
]
}
我有同樣的問題。你最終找到了解決方案嗎? 012scvscode也可以看到,但是當我構建它時,它會顯着失敗 – cramhead