Skip to content

Commit 7c681a9

Browse files
committed
Update TS guide
1 parent 3504693 commit 7c681a9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

versioned_docs/version-7.x/typescript.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
99

1010
React Navigation can be configured to type-check screens and their params, as well as various other APIs using TypeScript. This provides better intelliSense and type safety when working with React Navigation.
1111

12+
:::note
13+
14+
React Navigation is designed to work with [`strict`](https://www.typescriptlang.org/tsconfig/#strict) mode in TypeScript. If you are not using `strict` mode, some things might not work as expected.
15+
16+
:::
17+
1218
<Tabs groupId="config" queryString="config">
1319
<TabItem value="static" label="Static" default>
1420

@@ -187,6 +193,12 @@ The type containing the mapping must be a type alias (e.g. `type RootStackParamL
187193

188194
:::
189195

196+
If you have an [`id`](./navigator.md#id) prop for your navigator, you will also need to pass it as a generic:
197+
198+
```tsx
199+
const RootStack = createStackNavigator<RootStackParamList, 'MyStack'>();
200+
```
201+
190202
## Type checking screens
191203

192204
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.
@@ -211,7 +223,7 @@ The type takes 3 generics:
211223
- The name of the route the screen belongs to
212224
- The ID of the navigator (optional)
213225

214-
If you have an `id` prop for your navigator, you can do:
226+
If you have an [`id`](./navigator.md#id) prop for your navigator, you can do:
215227

216228
```ts
217229
type Props = NativeStackScreenProps<RootStackParamList, 'Profile', 'MyStack'>;

0 commit comments

Comments
 (0)