React-Native 使用typescript开发
百度了一圈发现都复杂的一批,要各种配置,步骤也很多。
其实初始化的时候,一行代码就可以了。
npx react-native init app --template react-native-template-typescript
如果之前安装了react-native-cli
那么就先卸载
npm uninstall -g react-native-cli
安卓运行的时候可能会红屏报错,unable to load script…
在android/app/build.gradle中添加:
project.ext.react = [
entryFile:"index.js",
enableHermes: false, // clean and rebuild if changing
bundleInDebug:true,
]
就能正常运行了