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-8.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
@@ -348,9 +348,7 @@ There are 2 steps to configure TypeScript with the dynamic API:
348
348
349
349
### Specifying the root navigator's type {#specifying-the-root-navigators-type-dynamic}
350
350
351
-
You can specify the type for your root navigator which will enable automatic type inference for [`useRoute`](use-route.md), [`useNavigation`](use-navigation.md), [`useNavigationState`](use-navigation-state.md), [`Link`](link.md), [`ref`](navigation-container.md#ref), [`linking`](navigation-container.md#linking) etc.
352
-
353
-
To do this, use module augmentation for `@react-navigation/native` and extend the `RootNavigator` interface with the type of your root navigator.
351
+
For the type-inference to work, React Navigation needs to know the type of the root navigator in your app. To do this, you can declare a module augmentation for `@react-navigation/native` and extend the `RootNavigator` interface with the type of your root navigator.
Here `RootStack` refers to the navigator used at the root of your app. The `RootStackParamList` type is covered in the next section.
375
373
374
+
This is needed to type-check hooks such as [`useNavigation`](use-navigation.md), [`useRoute`](use-route.md), [`useNavigationState`](use-navigation-state.md) etc.
375
+
376
376
### Specifying param types for screens {#specifying-param-types-for-screens-dynamic}
377
377
378
-
To type check route names and params, create an object type with mappings from route names to the params of each route. For example, say we have a route called `Profile` in our root navigator which should have a param `userId`:
378
+
To type check route names and params, we need to create an object type with mappings from route names to the params of each route. For example, say we have a route called `Profile` in our root navigator which should have a param `userId`:
379
379
380
380
```tsx
381
381
typeRootStackParamList= {
@@ -419,7 +419,7 @@ And then we can use it:
419
419
420
420
This will provide type checking and IntelliSense for props of the [`Navigator`](navigator.md) and [`Screen`](screen.md) components.
421
421
422
-
When a screen renders a nested navigator, use `NavigatorScreenParams` for that route. Define the child navigator first:
422
+
When a screen renders a nested navigator, use `NavigatorScreenParams` for that route. First, define and export the child navigator object:
0 commit comments