Skip to content

Commit 81e1ce6

Browse files
authored
Tweak TypeScript guide (#4601)
1 parent a99d2dd commit 81e1ce6

2 files changed

Lines changed: 20 additions & 26 deletions

File tree

docs/typescript.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ npx create-expo-app --template
2525
<TabItem value="npm">
2626

2727
```shell
28-
npm install -D @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript
28+
npm install -D typescript @react-native/typescript-config @types/jest @types/react @types/react-test-renderer
2929
```
3030

3131
</TabItem>
3232
<TabItem value="yarn">
3333

3434
```shell
35-
yarn add --dev @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript
35+
yarn add --dev typescript @react-native/typescript-config @types/jest @types/react @types/react-test-renderer
3636
```
3737

3838
</TabItem>
@@ -44,9 +44,9 @@ This command adds the latest version of every dependency. The versions may need
4444

4545
2. Add a TypeScript config file. Create a `tsconfig.json` in the root of your project:
4646

47-
```json
47+
```json title="tsconfig.json"
4848
{
49-
"extends": "@tsconfig/react-native/tsconfig.json"
49+
"extends": "@react-native/typescript-config"
5050
}
5151
```
5252

@@ -86,19 +86,16 @@ Out of the box, TypeScript sources are transformed by [Babel][babel] during bund
8686
You can provide an interface for a React Component's [Props](props) and [State](state) via `React.Component<Props, State>` which will provide type-checking and editor auto-completing when working with that component in JSX.
8787

8888
```tsx title="components/Hello.tsx"
89-
import React from 'react';
89+
import {useState} from 'react';
9090
import {Button, StyleSheet, Text, View} from 'react-native';
9191

9292
export type Props = {
9393
name: string;
9494
baseEnthusiasmLevel?: number;
9595
};
9696

97-
const Hello: React.FC<Props> = ({
98-
name,
99-
baseEnthusiasmLevel = 0,
100-
}) => {
101-
const [enthusiasmLevel, setEnthusiasmLevel] = React.useState(
97+
function Hello({name, baseEnthusiasmLevel = 0}: Props) {
98+
const [enthusiasmLevel, setEnthusiasmLevel] = useState(
10299
baseEnthusiasmLevel,
103100
);
104101

@@ -134,7 +131,7 @@ const Hello: React.FC<Props> = ({
134131
</View>
135132
</View>
136133
);
137-
};
134+
}
138135

139136
const styles = StyleSheet.create({
140137
container: {
@@ -168,8 +165,8 @@ To use custom path aliases with TypeScript, you need to set the path aliases to
168165

169166
```diff
170167
{
171-
- "extends": "@tsconfig/react-native/tsconfig.json"
172-
+ "extends": "@tsconfig/react-native/tsconfig.json",
168+
- "extends": "@react-native/typescript-config"
169+
+ "extends": "@react-native/typescript-config",
173170
+ "compilerOptions": {
174171
+ "baseUrl": ".",
175172
+ "paths": {

website/versioned_docs/version-0.79/typescript.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ npx create-expo-app --template
2525
<TabItem value="npm">
2626

2727
```shell
28-
npm install -D @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript
28+
npm install -D typescript @react-native/typescript-config @types/jest @types/react @types/react-test-renderer
2929
```
3030

3131
</TabItem>
3232
<TabItem value="yarn">
3333

3434
```shell
35-
yarn add --dev @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript
35+
yarn add --dev typescript @react-native/typescript-config @types/jest @types/react @types/react-test-renderer
3636
```
3737

3838
</TabItem>
@@ -44,9 +44,9 @@ This command adds the latest version of every dependency. The versions may need
4444

4545
2. Add a TypeScript config file. Create a `tsconfig.json` in the root of your project:
4646

47-
```json
47+
```json title="tsconfig.json"
4848
{
49-
"extends": "@tsconfig/react-native/tsconfig.json"
49+
"extends": "@react-native/typescript-config"
5050
}
5151
```
5252

@@ -86,19 +86,16 @@ Out of the box, TypeScript sources are transformed by [Babel][babel] during bund
8686
You can provide an interface for a React Component's [Props](props) and [State](state) via `React.Component<Props, State>` which will provide type-checking and editor auto-completing when working with that component in JSX.
8787

8888
```tsx title="components/Hello.tsx"
89-
import React from 'react';
89+
import {useState} from 'react';
9090
import {Button, StyleSheet, Text, View} from 'react-native';
9191

9292
export type Props = {
9393
name: string;
9494
baseEnthusiasmLevel?: number;
9595
};
9696

97-
const Hello: React.FC<Props> = ({
98-
name,
99-
baseEnthusiasmLevel = 0,
100-
}) => {
101-
const [enthusiasmLevel, setEnthusiasmLevel] = React.useState(
97+
function Hello({name, baseEnthusiasmLevel = 0}: Props) {
98+
const [enthusiasmLevel, setEnthusiasmLevel] = useState(
10299
baseEnthusiasmLevel,
103100
);
104101

@@ -134,7 +131,7 @@ const Hello: React.FC<Props> = ({
134131
</View>
135132
</View>
136133
);
137-
};
134+
}
138135

139136
const styles = StyleSheet.create({
140137
container: {
@@ -168,8 +165,8 @@ To use custom path aliases with TypeScript, you need to set the path aliases to
168165

169166
```diff
170167
{
171-
- "extends": "@tsconfig/react-native/tsconfig.json"
172-
+ "extends": "@tsconfig/react-native/tsconfig.json",
168+
- "extends": "@react-native/typescript-config"
169+
+ "extends": "@react-native/typescript-config",
173170
+ "compilerOptions": {
174171
+ "baseUrl": ".",
175172
+ "paths": {

0 commit comments

Comments
 (0)