Skip to content

Commit 8fb73d0

Browse files
committed
Fix some grammatical issues
1 parent 1e12308 commit 8fb73d0

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

versioned_docs/version-7.x/typescript.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ This is needed to type-check the `useNavigation` hook.
5959

6060
## Navigator specific types
6161

62-
Generally we recommend using the default types for the `useNavigation` prop to access the navigation object in a navigator agnostic manner. However, if you need to use navigator specific APIs, you need to manually annotate `useNavigation`:
62+
Generally, we recommend using the default types for the `useNavigation` prop to access the navigation object in a navigator-agnostic manner. However, if you need to use navigator-specific APIs, you need to manually annotate `useNavigation`:
6363

6464
```ts
6565
type BottomTabParamList = StaticParamList<typeof BottomTabNavigator>;
@@ -73,9 +73,7 @@ type ProfileScreenNavigationProp = BottomTabNavigationProp<
7373
const navigation = useNavigation<ProfileScreenNavigationProp>();
7474
```
7575

76-
This follows the same principle as the types described in [Type checking with TypeScript](typescript.md).
77-
78-
Note that annotating `useNavigation` this way not type-safe since we can't guarantee that the type you provided matches the type of the navigator.
76+
Note that annotating `useNavigation` this way is not type-safe since we can't guarantee that the type you provided matches the type of the navigator.
7977

8078
## Nesting navigator using dynamic API
8179

@@ -129,9 +127,9 @@ Now, when using `StaticParamList<typeof RootStack>`, it will include the screens
129127

130128
When using the dynamic API, it is necessary to specify the types for each screen as well as the nesting structure as it cannot be inferred from the code.
131129

132-
### Type checking the navigator
130+
### Typechecking the navigator
133131

134-
To type check our route name and params, the first thing we need to do is to create an object type with mappings for route name to the params of the route. For example, say we have a route called `Profile` in our root navigator which should have a param `userId`:
132+
To typecheck our route name and params, the first thing we need to do is to create an object type with mappings for route names to the params of the route. For example, say we have a route called `Profile` in our root navigator which should have a param `userId`:
135133

136134
```tsx
137135
type RootStackParamList = {
@@ -151,7 +149,7 @@ type RootStackParamList = {
151149

152150
Specifying `undefined` means that the route doesn't have params. A union type with `undefined` (e.g. `SomeType | undefined`) means that params are optional.
153151

154-
After we have defined the mappings, we need to tell our navigator to use it. To do that, we can pass it as a generic to the `createXNavigator` functions:
152+
After we have defined the mapping, we need to tell our navigator to use it. To do that, we can pass it as a generic to the `createXNavigator` functions:
155153

156154
```tsx
157155
import { createStackNavigator } from '@react-navigation/stack';
@@ -177,13 +175,13 @@ This will provide type checking and intelliSense for props of the `Navigator` an
177175

178176
:::note
179177

180-
The type containing the mappings must be a type alias (e.g. `type RootStackParamList = { ... }`). It cannot be an interface (e.g. `interface RootStackParamList { ... }`). It also shouldn't extend `ParamListBase` (e.g. `interface RootStackParamList extends ParamListBase { ... }`). Doing so will result in incorrect type checking where it allows you to pass incorrect route names.
178+
The type containing the mapping must be a type alias (e.g. `type RootStackParamList = { ... }`). It cannot be an interface (e.g. `interface RootStackParamList { ... }`). It also shouldn't extend `ParamListBase` (e.g. `interface RootStackParamList extends ParamListBase { ... }`). Doing so will result in incorrect type checking which allows you to pass incorrect route names.
181179

182180
:::
183181

184182
### Type checking screens
185183

186-
To type check our screens, we need to annotate the `navigation` and the `route` props received by a screen. The navigator packages in React Navigation export generic types to define types for both the `navigation` and `route` props from the corresponding navigator.
184+
To typecheck our screens, we need to annotate the `navigation` and the `route` props received by a screen. The navigator packages in React Navigation export generic types to define types for both the `navigation` and `route` props from the corresponding navigator.
187185

188186
For example, you can use `NativeStackScreenProps` for the Native Stack Navigator.
189187

@@ -266,7 +264,7 @@ import type { RouteProp } from '@react-navigation/native';
266264
type ProfileScreenRouteProp = RouteProp<RootStackParamList, 'Profile'>;
267265
```
268266

269-
We recommend creating a separate `types.tsx` file where you keep the types and import them in your component files instead of repeating them in each file.
267+
We recommend creating a separate file: `types.tsx` - where you keep the types and import from there in your component files instead of repeating them in each file.
270268

271269
### Nesting navigators
272270

@@ -307,7 +305,7 @@ type ProfileScreenProps = CompositeScreenProps<
307305
>;
308306
```
309307

310-
The `CompositeScreenProps` type takes 2 parameters, first parameter is the type of props for the primary navigation (type for the navigator that owns this screen, in our case the tab navigator which contains the `Profile` screen) and second parameter is the type of props for secondary navigation (type for a parent navigator). The primary type should always have the screen's route name as its second parameter.
308+
The `CompositeScreenProps` type takes 2 parameters, the first parameter is the type of props for the primary navigation (type for the navigator that owns this screen, in our case the tab navigator which contains the `Profile` screen) and the second parameter is the type of props for secondary navigation (type for a parent navigator). The primary type should always have the screen's route name as its second parameter.
311309

312310
For multiple parent navigators, this secondary type should be nested:
313311

@@ -463,7 +461,7 @@ Specifying this type is important if you heavily use `useNavigation`, `Link` etc
463461

464462
When writing types for React Navigation, there are a couple of things we recommend to keep things organized.
465463

466-
1. It's good to create a separate files (e.g. `navigation/types.tsx`) which contains the types related to React Navigation.
464+
1. It's good to create a separate file (e.g. `navigation/types.tsx`) that contains the types related to React Navigation.
467465
2. Instead of using `CompositeNavigationProp` directly in your components, it's better to create a helper type that you can reuse.
468466
3. Specifying a global type for your root navigator would avoid manual annotations in many places.
469467

0 commit comments

Comments
 (0)