【发布时间】:2018-10-12 19:54:40
【问题描述】:
我正在尝试将 TypeScript 添加到 React-Native Expo 项目中,如果我将任何文件 abc.js 重命名为 abc.tsx,则会收到以下错误:
我一直按照以下说明操作:
- https://facebook.github.io/react-native/blog/2018/05/07/using-typescript-with-react-native
- https://medium.com/@rintoj/react-native-with-typescript-40355a90a5d7
我该如何解决这个问题?
rn-cli.config.js
module.exports = {
getTransformModulePath() {
return require.resolve('react-native-typescript-transformer');
},
getSourceExts() {
return ['ts', 'tsx', 'js', 'jsx'];
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"jsx": "react",
"outDir": "./dist",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
//"strict": true,
"skipLibCheck": true,
"declaration": true,
"noUnusedLocals": true
},
"exclude": [
"node_modules"
]
}
【问题讨论】:
-
您不需要创建 rn-cli.config.js 。您可以在 app.json 中添加元素,让打包者知道您使用 ts
标签: typescript react-native expo