mirror of
https://github.com/zhigang1992/examples.git
synced 2026-01-12 22:47:03 +08:00
Merge pull request #93 from byCedric/feat/with-typescript
feat: add typescript example from new expo init
This commit is contained in:
19
with-typescript/App.tsx
Normal file
19
with-typescript/App.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text>Open up App.tsx to start working on your app!</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#fff',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
});
|
||||
30
with-typescript/README.md
Normal file
30
with-typescript/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# [TypeScript Example](https://www.typescriptlang.org/)
|
||||
|
||||
<p>
|
||||
<!-- iOS -->
|
||||
<img alt="Supports Expo iOS" longdesc="Supports Expo iOS" src="https://img.shields.io/badge/iOS-4630EB.svg?style=flat-square&logo=APPLE&labelColor=999999&logoColor=fff" />
|
||||
<!-- Android -->
|
||||
<img alt="Supports Expo Android" longdesc="Supports Expo Android" src="https://img.shields.io/badge/Android-4630EB.svg?style=flat-square&logo=ANDROID&labelColor=A4C639&logoColor=fff" />
|
||||
<!-- Web -->
|
||||
<img alt="Supports Expo Web" longdesc="Supports Expo Web" src="https://img.shields.io/badge/web-4630EB.svg?style=flat-square&logo=GOOGLE-CHROME&labelColor=4285F4&logoColor=fff" />
|
||||
</p>
|
||||
|
||||
TypeScript is a superset of JavaScript which gives you static types and powerful tooling in Visual Studio Code including autocompletion and useful inline warnings for type errors.
|
||||
|
||||
## 🚀 How to use
|
||||
|
||||
#### Creating a new project**
|
||||
|
||||
- Install the CLI: `npm i -g expo-cli`
|
||||
- Create a project: `expo init --template expo-template-blank-typescript`
|
||||
- `cd` into the project
|
||||
|
||||
### Adding TypeScript to existing projects
|
||||
|
||||
- Copy the `tsconfig.json` from this repo, or new typescript template
|
||||
- Add typescript dependencies: `yarn add --dev @types/react @types/react-native typescript`
|
||||
- Rename files tpo TypeScript, `.tsx` for React components and `.ts` for plain typescript files
|
||||
|
||||
## 📝 Notes
|
||||
|
||||
- [Expo TypeScript guide](https://docs.expo.io/versions/latest/guides/typescript/)
|
||||
12
with-typescript/app.json
Normal file
12
with-typescript/app.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"expo": {
|
||||
"name": "with-typescript",
|
||||
"version": "1.0.0",
|
||||
"icon": "https://github.com/expo/expo/blob/master/templates/expo-template-blank/assets/icon.png?raw=true",
|
||||
"splash": {
|
||||
"image": "https://github.com/expo/expo/blob/master/templates/expo-template-blank/assets/splash.png?raw=true",
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
}
|
||||
}
|
||||
6
with-typescript/babel.config.js
Normal file
6
with-typescript/babel.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = function(api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: ['babel-preset-expo'],
|
||||
};
|
||||
};
|
||||
17
with-typescript/package.json
Normal file
17
with-typescript/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"expo": "~36.0.0",
|
||||
"react": "~16.9.0",
|
||||
"react-dom": "~16.9.0",
|
||||
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
|
||||
"react-native-screens": "2.0.0-alpha.12",
|
||||
"react-native-web": "~0.11.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "~16.9.0",
|
||||
"@types/react-native": "~0.60.23",
|
||||
"@babel/core": "~7.0.0",
|
||||
"babel-preset-expo": "~8.0.0",
|
||||
"typescript": "~3.6.3"
|
||||
}
|
||||
}
|
||||
11
with-typescript/tsconfig.json
Normal file
11
with-typescript/tsconfig.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"jsx": "react-native",
|
||||
"lib": ["dom", "esnext"],
|
||||
"moduleResolution": "node",
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user