You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/typescript.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ There are 2 steps to configure TypeScript with the static API:
35
35
}
36
36
```
37
37
38
-
2. Declare a module augmentation for `@react-navigation/core` and extend the `RootNavigator` interface with the type of your root navigator.
38
+
2. Declare a module augmentation for `@react-navigation/native` and extend the `RootNavigator` interface with the type of your root navigator.
39
39
40
40
```ts
41
41
const HomeTabs =createBottomTabNavigator({
@@ -55,7 +55,7 @@ There are 2 steps to configure TypeScript with the static API:
55
55
typeRootStackType=typeofRootStack;
56
56
57
57
// highlight-start
58
-
declaremodule'@react-navigation/core' {
58
+
declaremodule'@react-navigation/native' {
59
59
interfaceRootNavigatorextendsRootStackType {}
60
60
}
61
61
// highlight-end
@@ -501,14 +501,14 @@ const navigationRef =
501
501
502
502
Instead of manually annotating these APIs, you can specify the type of your root navigator, which will be used to infer the default types.
503
503
504
-
To do this, you can use module augmentation for `@react-navigation/core` and extend the `RootNavigator` interface with the type of your root navigator:
504
+
To do this, you can use module augmentation for `@react-navigation/native` and extend the `RootNavigator` interface with the type of your root navigator:
@@ -114,10 +117,13 @@ function FeedScreen(_: Props) {
114
117
In the above snippet:
115
118
116
119
1. We first define the param list type for screens in the navigator that defines params for each screen
117
-
2. Then we use the `NavigatorScreenParams` type to get the type of route's `params` which will include types for the nested screens
118
-
3. Finally, we use the type of `params` with `StaticScreenProps` to define the type of the screen component
120
+
2. Then we create the dynamic navigator with that param list
121
+
3. Then we use the `NavigatorScreenParams` type with `typeof FeedTabs` to get the type of route's `params` which will include types for the nested screens and the concrete navigator type
122
+
4. Finally, we use the type of `params` with `StaticScreenProps` to define the type of the screen component
119
123
120
-
This is based on how we'd define the type for a screen with a nested navigator with the dynamic API. See [Type checking screens and params in nested navigator](typescript.md#type-checking-screens-and-params-in-nested-navigator).
124
+
Using `typeof FeedTabs` lets typed hooks such as `useNavigation('Latest')`, `useRoute('Latest')`, and `useNavigationState('Latest', selector)` infer the screens inside the nested tab navigator.
125
+
126
+
This is based on how we'd define the type for a screen with a nested navigator with the dynamic API. See [Specifying param types for screens](typescript.md#specifying-param-types-for-screens-dynamic).
@@ -168,21 +174,15 @@ To use the `FeedTabs` navigator for the `Feed` screen, we need to get a componen
168
174
constFeedScreen=FeedTabs.getComponent();
169
175
```
170
176
171
-
In addition, we can generate the TypeScript types for the `FeedTabs` navigator and use it in the types of `RootStack` without needing to write them manually:
177
+
In addition, we can use the type of the `FeedTabs` navigator in the types of `RootStack`:
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/troubleshooting.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -467,8 +467,8 @@ This usually means that TypeScript doesn't know the route names and params for y
467
467
468
468
Ensure the following:
469
469
470
-
- You have configured global types for your navigator. See [specifying root navigator type](typescript.md#specify-the-root-navigators-type).
471
-
- If you are using the dynamic API, you have provided a param list as a generic (e.g. `createStackNavigator<MyParamList>()`) and that your screen names match the keys in that param list. See [type checking the navigator](typescript.md#typechecking-the-navigator).
470
+
- You have configured global types for your navigator. See [specifying the root navigator's type](typescript.md#specifying-the-root-navigators-type).
471
+
- If you are using the dynamic API, you have provided a param list as a generic (e.g. `createStackNavigator<MyParamList>()`) and that your screen names match the keys in that param list. See [specifying param types for screens](typescript.md#specifying-param-types-for-screens-dynamic).
472
472
473
473
## Screens are unmounting/remounting during navigation
0 commit comments